2013-04-04 91 views
0

我看了不少Q & A的關於選擇MIN值從列名即 ​​ 但我的問題沒有得到解決。選擇最小值查詢

SELECT MIN(column1 + (5 * 24 * 60 * 60) AS deadline1, column2 +(1 * 24 * 60 * 60) AS deadline2) AS deadline FROM table_name 

顯示錯誤代碼Error Code : 1064

我如何選擇這兩個值的最小值?任何想法PLZ?

+0

你不應該有'函數調用 – Barmar 2013-04-04 09:21:18

+0

內AS'條款請看看http://stackoverflow.com/questions/368351/whats-the-best-way-select-the-minimum-value-from-multiple-columns – 2013-04-04 09:22:16

+0

@ChetterHummin這是SQL Server,而不是MySQL。 – Barmar 2013-04-04 09:23:29

回答

4

MySQL僅使用MIN作爲聚合函數。要選擇最小的幾個表情,你必須使用LEAST

SELECT LEAST(column1 + (5 * 24 * 60 * 60), column2 +(1 * 24 * 60 * 60)) AS deadline FROM table_name 
+0

工作出色(Y) – Suleman 2013-04-04 09:26:55