首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL 话语合并

2012-09-09 
SQL 语句合并数据库SQL2000以下两条语句,如何合并成一条:SQL codeselect qid,count(qid) as cis from test

SQL 语句合并
数据库SQL2000
以下两条语句,如何合并成一条:

SQL code
select qid,count(qid) as cis from test group by qid

SQL code
select * from test as t1 where exists(select * from test as t2 where t1.QID=t2.ID) and t1.TID="&TID&"


 
请大家帮帮忙

[解决办法]
SQL code
select *,(select count(*) from test where qid=t1.qid)from test as t1 where exists(select * from test as t2 where t1.QID=t2.ID) and t1.TID="&TID&"
[解决办法]
貌似LZ的那两条select语句没有什么关联,为何要合并呢?
[解决办法]
SQL code
select qid,count(qid) as cis from (select * from test as t1 where exists(select * from test as t2 where t1.QID=t2.ID) and t1.TID="&TID&") z group by qid
[解决办法]
SQL code
select *,       (select count(*) from test where qid=t1.qid)          from test as t1         where exists              (select * from test as t2 where t1.QID=t2.ID) and t1.TID="&TID&" 

热点排行