gmth.net
当前位置:首页 >> sql中多表查询 还有COUNT >>

sql中多表查询 还有COUNT

select a. col1, b.col2 from (select count(id) as col1 from table1) as a, (select count(id) as col2 from table2) as b -------------这样写。

select tat.id ,tat.name ,count(tbt.id) as numbersd from test_a_temp tat,test_b_temp tbt where tbt.no=tat.id group by tat.id,tat.name order by numbersd desc 其中 test_a_temp 就是你那个A表,test_b_temp 就是B表 A中有两列 ID,NAME ...

除了count之外还有一个函数叫做 SUM。 SELECT paperName , COUNT (1) AS 总题数 , sum (CASE WHEN statu = 1 THEN 1 ELSE 0 END) AS 审核题数FROM questionGROUP BY paperNmepapername in(select distinct paperName from question) 这个没意义...

select a.content ,count(u.articleId)from article a,user u where a.id = u.articleId and a.artilceName = 'pumpkin'

可以这样写: select (select count(*) from bumen)+(select count(*) from mrs) as sum_count 如果两个表结果相同的话,也可以用 select count(*) as sum_count from ( select * from A union all select * from B ) as tmp

select a.栏目,count(b.文章) from sortlist a,article b where a.sortid=b.sortid group by a.栏目;

可以有两种解决方法。 方法1: SELECT paperName , COUNT (1) AS 总题数 , sum (CASE WHEN statu = 1 THEN 1 ELSE 0 END) AS 审核题数 FROM question GROUP BY paperNme 方法2: select s.总题数, s.审核题数, s.paperName from ( select COUNT(...

可以有两种解决方法, 所需工具:SQL 查询两个count的方法1: SELECT paperName , COUNT (1) AS 总题数 , sum (CASE WHEN statu = 1 THEN 1 ELSE 0 END) AS 审核题数FROM questionGROUP BY paperNme 查询两个count的方法2: select s.总题数, s.审...

假设两张表分别为TAB1,TAB2: SELECT SUM(CNT) FROM ( SELECT COUNT(1) CNT FROM TAB1 WHERE 满足条件A,B,C UNION ALL SELECT COUNT(1) CNT FROM TAB2 WHERE 满足条件A,B,C)

oracle: select (select count(1) from tab1) + (select count(1) from tab2) + ... + (select count(1) from tabN) from dual DB2: select (select count(1) from tab1) + (select count(1) from tab2) + ... + (select count(1) from tabN) fr...

网站首页 | 网站地图
All rights reserved Powered by www.gmth.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com