如何组合这两个查询?

时间:2013-10-23 17:32:51

标签: sql ms-access

我有来自MS Access的2个查询: 查询1:

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

运行查询1后,我获得了唯一用户列表并运行查询2以获取总计数:

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

如何将其转换为SQL studio脚本以获取唯一身份用户,然后计算Date中的总数?请指教,谢谢!

2 个答案:

答案 0 :(得分:2)

不需要子查询,请尝试:

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

根据评论:

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

答案 1 :(得分:2)

试试这样:

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