有点奇怪的请求,但是是否可以在不使用外连接的情况下让单独的 TSQL 查询并排显示数据?我想知道我是否完全复杂化了这个......
这是我想要做的:
我有 12 个查询可以计算记录数,我希望它们不是堆叠在一起,而是从右到左显示记录,就好像它们在表中一样。
所以从这些查询中:
SELECT COUNT(*) AS 'INTERNET JAN 12'
FROM dbo.CONTACT AS AA
JOIN dbo.Document AS BB
ON AA.ACCOUNTNO = BB.ACCOUNTNO
WHERE SOURCE IN ('INTERNET', 'EBAY', 'MSN', 'BING', 'GOOGLE', 'YAHOO')
AND KEY1 = 'EA'
AND MONTH(BB.Date) = 1
AND YEAR(BB.Date) = 2012
SELECT COUNT(*) AS 'INTERNET FEB 12'
FROM dbo.CONTACT AS AA
JOIN dbo.Document AS BB
ON AA.ACCOUNTNO = BB.ACCOUNTNO
WHERE SOURCE IN ('INTERNET', 'EBAY', 'MSN', 'BING', 'GOOGLE', 'YAHOO')
AND KEY1 = 'EA'
AND MONTH(BB.Date) = 2
AND YEAR(BB.Date) = 2012
...
SELECT COUNT(*) AS 'INTERNET DEC 12'
FROM dbo.CONTACT AS AA
JOIN dbo.Document AS BB
ON AA.ACCOUNTNO = BB.ACCOUNTNO
WHERE SOURCE IN ('INTERNET', 'EBAY', 'MSN', 'BING', 'GOOGLE', 'YAHOO')
AND KEY1 = 'EA'
AND MONTH(BB.Date) = 12
AND YEAR(BB.Date) = 2012
我希望结果集如下所示:
INTERNET JAN 12 INTERNET FEB 12 ... INTERNET DEC 12
12 25 31
而不是这样:
INTERNET JAN 12
12
INTERNET FEB 12
25
...
INTERNET DEC 12
31
如果不添加另一个字段并进行外部连接,这是否可能?最终结果是在 Excel 电子表格中将其作为最终用户自动更新的查询。