有以下几个查询结果,想要拼成一张表
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
时间: 2024-12-25 04:40:35