我需要顯示提出最大查詢次數的用戶及其部門的名稱。我通過加入5個表格來編寫以下查詢; user
,query
,profile
,degree
和department
。別名在查詢中不起作用
問題在於結果別名未被用於列名稱。對於這兩種列看起來像剛纔name
select user.name 'USER_NAME',department.name 'DEPT_NAME'
from user
inner join query on (query.user_id=user.id)
inner join profile on (user.profile_id=profile.id)
inner join degree on (profile.degree_id=degree.id)
inner join department on (degree.department_id=department.id)
group by user.name
order by count(query.id) desc
limit 1
別名應該沒有單引號 –