首页 > 其他 > 详细

如何将多个查询结果拼成一张表

时间:2014-06-27 21:59:22      阅读:501      评论:0      收藏:0      [点我收藏+]

有以下几个查询结果,想要拼成一张表

1.SELECT NAME,COUNT(1) AS Num1 FROM 表1 GROUP BY NAME;

2.SELECT NAME,COUNT(1) AS Num2 FROM 表1 WHERE EXC= 0 GROUP BY NAME;

注:EXC数据类型为bit

3.SELECT NAME,COUNT(1)AS Num3 FROM 表2 GROUP BY NAME;

4.SELECT NAME,COUNT(1)AS Num4 FROM 表2 WHERE DELETED=0 AND INDEXED=0 GROUP BY NAME;

5.SELECT NAME,CONVERT(varchar(11) ,ENTERTIME, 120) AS ‘Date‘ FROM 表3

 

如何将这五个查询结果拼成一张表?联合查询

SELECT NAME,COUNT(1) AS Num1, SUM( CASE WHEN EXC=1 THEN 1 ELSE 0 END) AS Num2,
(SELECT COUNT(1) FROM 表2 WHERE NAME=表1.NAME) AS Num3,
(SELECT COUNT(1) FROM 表2 WHERE DELETED=0 AND INDEXED=0 and NAME=表1.NAME) AS Num4,
(SELECT CONVERT(varchar(11) ,ENTERTIME, 120) FROM 表3 WHERE NAME=表1.NAME) AS ‘Date‘

FROM 表1
GROUP BY NAME

如何将多个查询结果拼成一张表,布布扣,bubuko.com

如何将多个查询结果拼成一张表

原文:http://www.cnblogs.com/kangjing/p/3807376.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!