我有兩個表分組的記錄:COUNT(*)按日期橫跨兩個表
emailLog表:
email sendTime sourceTag
-------------------------------------------------------
[email protected] 2016-11-17 09:14:37.213 WelcomeEmail
[email protected] 2016-11-16 09:14:37.213 WelcomeEmail
[email protected] 2016-11-15 09:12:33.213 WelcomeEmail
註冊表:
email dateRegistered regSource
-------------------------------------------------------
[email protected] 2016-11-17 09:14:37.213 WelcomeEmail
[email protected] 2016-11-16 09:14:37.213 WelcomeEmail
[email protected] 2016-11-15 09:12:33.213 WelcomeEmail
我試圖執行聯合查詢,以顯示在給定日期收到電子郵件的人與COUNT()的COUNT()比較德隆誰已登記在給定日期
我已經儘量得到就象這樣:
SELECT
CONVERT(varchar(10), sendTime, 120) as date,
COUNT(*) as numberSent
FROM emailLog
WHERE sourceTag = 'WelcomeEmail'
AND
sendTime BETWEEN '20161110' and '20161120'
GROUP BY
CONVERT(varchar(10), sendTime, 120)
ORDER BY DATE ASC;
,給了我一個特定sourceTag發送的電子郵件的列表,通過日期分組:
DATE NUMBERSENT
2016-11-17 256
2016-11-18 136
2016-11-19 40
2016-11-20 118
2016-11-21 186
但我無法弄清楚如何加入註冊的總和與來源,日期+,如:
DATE NUMBERSENT MEMBERSREGISTERED
2016-11-17 256 12
2016-11-18 136 24
2016-11-19 40 13
2016-11-20 118 2
2016-11-21 186 11
我曾試圖做類似...
SELECT
(SELECT count(*) from emailLog)
as emailLogResults,
(select count(*) from registrations)
as registrationResults
...
但是我被卡住之後。非常感謝的任何幫助
我刪除了不兼容的數據庫標籤。請標記您真正使用的數據庫。 –