有一個名爲「記錄」的表。如何選擇日期列表中的時間範圍?
userid | date
------ | ------
1 | 2017-08-21
1 | 2017-08-22
2 | 2017-08-22
1 | 2017-08-23
3 | 2017-08-23
現在我需要三個SQL來計算用戶ID。
select count(DISTINCT userid) from record where date between 2017-08-21 and 2017-08-23;
結果:3
select count(DISTINCT userid) from record where date between 2017-08-22 and 2017-08-23;
結果:3
select count(DISTINCT userid) from record where date between 2017-08-23 and 2017-08-23;
結果:2
我想指望那些由一個時間,可能有人能幫我解決這個好嗎?
我不明白。你試圖得到什麼結果? – Barmar
不知道你在問什麼。 「我想要數一次」是什麼意思? – Chiperific