SQL的连接问题,请高手帮忙

yesjoy 2006-10-10 03:14:54
1、select count(t1.id) as count1 from Table1 t1 where condition1
2、select count(t2.id) as count2 from Table2 t2 where condition2
上面两条语句是在同一个表中查询出两个结果,比如:
语句1得到结果为10
语句2得到结果为20
我现在希望得到下面的结果:
count1 count2
10 20
我用left join好象有问题
select tt1.count1,tt2.count2 from
(select count(t1.id) as count1 from Table1 t1 where condition1) tt1
left join
(select count(t2.id) as count2 from Table1 t2 where condition2) tt2


...全文
176 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yesyesyes 2006-10-10
  • 打赏
  • 举报
回复
两表没有关系的话,不能join
DengXingJie 2006-10-10
  • 打赏
  • 举报
回复
正解

mugua604 2006-10-10
  • 打赏
  • 举报
回复
你数据连接,要什么left join?
select
(select count(t1.id) from Table1 t1 where condition1) count1,
(select count(t2.id) from Table2 t2 where condition2) count2
akuzou 2006-10-10
  • 打赏
  • 举报
回复
select
(select count(t1.id) from Table1 t1 where condition1) count1,
(select count(t2.id) from Table2 t2 where condition2) count2

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧