phpmyadmin 当我创建VIEW时,得到的结果是错误的,而简单的SQL查询得到的结果是正确的

klr1opcd  于 2022-11-09  发布在  PHP
关注(0)|答案(1)|浏览(95)

下面是我为VIEW定义规则的方法:

SELECT `yearByWeek`, `week`, ( SELECT MIN(dolphin_day.date) ) AS 'start', ( SELECT SUM(dolphin_day.countHour)) AS 'countHours'

FROM `dolphin_day`
GROUP BY `yearByWeek`, `week`
ORDER BY `yearByWeek` DESC, `week` DESC

VIEW的错误结果如下:

SQL查询的正确结果:

为什么观点的结果是完全错误的?

axkjgtzd

axkjgtzd1#

聚合不应在子查询中。

SELECT `yearByWeek`, `week`, MIN(date) AS 'start', SUM(countHour) AS 'countHours'
FROM `dolphin_day`
GROUP BY `yearByWeek`, `week`
ORDER BY `yearByWeek` DESC, `week` DESC

相关问题