This is how I define a rule for my 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
❌ wrong result for VIEW is the following:
✅ correct result for SQL Query:
Why result for view is totally wrong?
CodePudding user response:
The aggregations shouldn't be in subqueries.
SELECT `yearByWeek`, `week`, MIN(date) AS 'start', SUM(countHour) AS 'countHours'
FROM `dolphin_day`
GROUP BY `yearByWeek`, `week`
ORDER BY `yearByWeek` DESC, `week` DESC