我有一个带有“Clicks”表的 MySQL 数据库。有一个“已创建”列(日期时间),我想对其进行分组并选择年、月和日部分。我想计算特定日期范围(startDate 和 endDate)内每天的记录。
var query = from c in scope.Entities.Clicks
where c.Created >= startDate && c.Created <= endDate
group c by new {c.Created.Year, c.Created.Month, c.Created.Day}
into grouped
select new {
Year = grouped.Key.Year,
Month = grouped.Key.Month,
Day = grouped.Key.Day,
Clicks = grouped.Count()
};
这会产生一个错误的查询:
SELECT
`GroupBy1`.`K1` AS `C1`,
`GroupBy1`.`K2` AS `C2`,
`GroupBy1`.`K3` AS `C3`,
`GroupBy1`.`K4` AS `C4`,
`GroupBy1`.`A1` AS `C5`
FROM (SELECT
COUNT(1) AS `A1`
FROM `Click` AS `Extent1`
WHERE (`Extent1`.`Created` >= @p__linq__0) AND (`Extent1`.`Created` <= @p__linq__1)
GROUP BY
1,
YEAR(`Extent1`.`Created`),
MONTH(`Extent1`.`Created`),
DAY(`Extent1`.`Created`)) AS `GroupBy1`
出现错误:MySql.Data.MySqlClient.MySqlException: Can't group on 'A1'
我做错了什么?或者这是一个 MySql 连接器错误?我尝试了 MySQL 连接器 6.5.4 和 6.6.5