本期中我的表格有三列:Player,Team和Date_Played。
Player Team Date_Played
John Smith New York 2/25/2014
Joe Smith New York 2/25/2014
Steve Johnson New York 2/25/2014
Steph Curry Orlando 2/25/2014
Frank Anthony Orlando 2/26/2014
Brian Smith New York 2/26/2014
Steve Johnson New York 2/27/2014
Steph Curry New York 2/28/2014
我知道如何获得一个不同的团队名称或日期的列表,但我正在寻找的是一个将按团队分组并计算不同团队和团队数量的查询。日期组合。所以输出应该如下所示:
Team Count
New York 4
Orlando 2
到目前为止,我有:
SELECT DISTINCT Tm, Count(Date_Played) AS Count
FROM NBAGameLog
GROUP BY NBAGameLog.[Tm];
但这给了我按日期分组的记录总数。
答案 0 :(得分:4)
此查询已在Access 2010中进行了测试:
SELECT Team, Count(Date_Played) AS Count
FROM
(
SELECT DISTINCT Team, Date_Played
FROM NBAGameLog
) AS whatever
GROUP BY Team
答案 1 :(得分:4)
少一点代码:
// $entity is an proxy object from doctrine
$relectionClass = new \ReflectionClass($entity);
$properties = $class->getProperties();
它显示与第一个答案相同的执行计划。
答案 2 :(得分:2)
如果我理解你,你正在寻找这样的查询:
SELECT x.Team, count(*)
FROM
(SELECT Team, Date_Played
FROM NBAGameLog
GROUP BY Team, Date_Played) AS x
GROUP BY x.Team