1

我有来自 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 的总数?请指教,谢谢!

4

2 回答 2

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
于 2013-10-23T17:37:25.990 回答
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
于 2013-10-23T17:37:39.927 回答