Quote:
Originally Posted by jdcowboy
those attributes that do not appear in GROUP BY clause can appear in SELECT clause ONLY if they are aggregated.
|
yes, that indeed is the problem
other database systems will actually generate a syntax error if there are un-aggregated columns in the SELECT clause that are missing from the GROUP BY (what mysql calls "
hidden" columns)
you can try to fix this error by un-hiding them, adding them to the GROUP BY --
Code:
SELECT id
, ord_id
, status_id
, MAX(dt)
FROM daTable
GROUP
BY id
, ord_id
, status_id
but that's not actually a solution because there is only one row per id, and its date will be the maximum date for that id
or, you can try to fix the error by making the hidden columns aggregates, thereby keeping the originally intended GROUP BY --
Code:
SELECT MIN(id)
, ord_id
, AVG(status_id)
, MAX(dt)
FROM daTable
GROUP
BY ord_id
but that's not actually a solution either, because the aggregate values that you get for the hidden columns won't necessarily come from the same row that has the maximum date
that's why it's not a simple query
