求教各位大神2表查询的 - MS-SQL Server / 疑难问题
表T_Kind K_ID K_Name K_Kind
1 球 0
2 人 0
3 篮球 1
4 足球 1
5 男人 2
5 妖人 2
表T_P P_ID P_Name P_Kind
1 乒乓球 1
2 NBA 3
表T_P的P_Kind和表T_Kind的K_ID 对应。我现在想查出T_P表中根据表T_Kind关联的那2条记录:
SQL code:
--> 测试数据:#T_Kind
if object_id('tempdb.dbo.#T_Kind') is not null drop table #T_Kind
go
create table #T_Kind([K_ID] int,[K_Name] varchar(4),[K_Kind] int)
insert #T_Kind
select 1,'球',0 union all
select 2,'人',0 union all
select 3,'篮球',1 union all
select 4,'足球',1 union all
select 5,'男人',2 union all
select 5,'妖人',2
--> 测试数据:#T_P
if object_id('tempdb.dbo.#T_P') is not null drop table #T_P
go
create table #T_P([P_ID] int,[P_Name] varchar(6),[P_Kind] int)
insert #T_P
select 1,'乒乓球',1 union all
select 2,'NBA',3
--------------------------------查询开始------------------------------
select t.* from #T_Kind t,#T_P p where t.K_ID = p.[P_Kind]
/*
K_ID K_Name K_Kind
----------- ------ -----------
1 球 0
3 篮球 1
(2 行受影响)
*/
是这个意思吗?
sel
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......
原SQL语句SQL code:
SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......
现在有一个部门表dept(部门名称,部门号。。)有一个人员表emp(姓名,人员编号,职位,薪资,部门)
emp表中的内容是这样的:
a 1 工程师 3000 软件部
b 2 普通员工 2000 硬件部
c 3 工程师 4000 硬件部
d ......