2012-12-02 60 views
0

我的查詢中有錯誤。下面是該查詢:SQL語法錯誤,我沒有看到它

select HourTime, count(*) from 
(
select substring(time,1,2) as HourTime, count(*) as ActivityCount 
from htmp_cs368 a 
group by HourTime 
)htmp 
union 
(
select substring(time,1,2) as HourTime, count(*) as ActivityCount 
from atmp_cs368 a 
group by HourTime 
)atmp 
group by HourTime DESC 

這裏是錯誤消息:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that  corresponds to your MySQL server version for the right syntax to use near 'atmp 
group by HourTime DESC' at line 12 

任何人都可以看到它在我的錯誤是什麼?我很感激。這是alger程序的一部分,因此是java標籤。

+0

爲什麼這個標記爲 「Java」 的!?這是純粹的SQL ... – tuga

回答

7

GROUP BY沒有訂單。你需要排序ORDER BY

GROUP BY HourTime 
ORDER BY HourTime DESC 
+0

謝謝,我也需要刪除'atmp'。 –

1

我想你的意思是:

... 
group by HourTime 
order by HourTime desc