用于获取表中计数的SELECT语句

use*_*284 0 sql select

我有一个表"下载",其中包含以下信息:

objKey     CustNum    UserId    DownloadDate
51048879   123        7654       2014-09-01
51048879   234        32434      2014-09-02
51048879   123        7654       2014-09-01
51047379   2132       3456       2014-08-20
51048879   2132       9786       2014-09-01
51047379   123        7654       2014-09-02
Run Code Online (Sandbox Code Playgroud)

我希望通过downloadDate了解下载了多少产品,客户和用户.所以我想要:

DownloadDate      Products       Customers    Users
2014-09-01         1              2            2
2014-09-02         2              2            2
2014-08-20         1              1            1
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决SELECT语句吗?我每次尝试都会得到错误的数字.我认为这应该比我尝试的更容易.

jue*_*n d 5

select downloaddate,
       count(distinct objkey) as products,
       count(distinct custnum) as customers,
       count(distinct userid) as users
from downloads
group by downloaddate
Run Code Online (Sandbox Code Playgroud)


Gor*_*off 5

你想要的count(distinct).我认为这样做你想要的:

select DownloadDate, count(distinct objKey) as Products,
       count(distinct CustNum) as Customers,
       count(distinct UserId) as Users
from table t
group by DownloadDate
order by DownloadDate;
Run Code Online (Sandbox Code Playgroud)