简体   繁体   English

如何组合这两个查询?

[英]How do I combine these two queries?

I have 2 queries from MS Access: Query 1: 我有来自MS Access的2个查询:查询1:

Select Date, Username
From Table1
where Date>='9/1/2013'
group by Date, Username

After run the Query 1, I got the unique users list and run Query 2 to get the total counts: 运行查询1后,我获得了唯一用户列表并运行查询2以获取总计数:

Select Query1.Date, Count(Query1.Date)
from Query1
Where Date>='9/1/2013'

How do I translate this into SQL studio script to get unique users then count the total numbers from Date? 如何将其转换为SQL Studio脚本以获取唯一用户,然后计算Date中的总数? Please advise, thank you! 请指教,谢谢!

There's no need for a sub query, try this: 不需要子查询,试试这个:

SELECT Date, Count (date)
FROM Database.User.Table1 
Where Date > '9/1/2013' 
Group By date, username

Per the comments: 根据评论:

SELECT Date, username, Count (date)
FROM Database.User.Table1 
Where Date >= '9/1/2013' 
Group By date, username

Try it like this: 试试这样:

Select q.Date, Count(q.Date)
FROM (
    Select Date, Username
    From Table1
    where Date>='9/1/2013'
    group by Date, Username
) q
GROUP BY q.Date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM