易截截图软件、单文件、免安装、纯绿色、仅160KB

求教各位大神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


相关问答:

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号