SELECT *
FROM
(
SELECT com_jobcard.job_card_num,
sum(worked_qty),employee.emp_name
FROM timer_completed
INNER JOIN process ON process.id = timer_completed.process_id
INNER JOIN com_jobcard ON com_jobcard.id = timer_completed.job_card_id
INNER JOIN employee ON employee.id = timer_completed.employee_id
AND process.id = '611'
AND timer_completed.group_id = '60'
AND timer_completed.report_date = DATE_ADD(CURDATE(), INTERVAL -1 DAY)
ORDER BY com_jobcard.id DESC
) AS tmp_table
GROUP BY com_jobcard.job_card_num
使用GROUPBY和ORDERBY在這段代碼中我使用Group by
選項,但我需要的結果的遞減順序com_jobcard.id
如果我使用它返回上面的查詢:在同一查詢
#1054
- 未知' 語句'中的'com_jobcard.job_card_num'列。
請幫幫我。
你想完成什麼?您的查詢不是真正有效的SQL。即使您可以讓MySQL接受它,您的查詢也會使用(錯誤)功能,其中MySQL允許'select'中不在'group by'中的任何列。所以,像'emp_name'這樣的列會得到*不確定的*值。 –