2017-03-01 50 views

回答

2

你可以命令的結果,並採取的第一條記錄:

SELECT speed, time 
FROM  info 
WHERE id = 1 AND time > 1234 
ORDER BY speed DESC 
LIMIT 1 
+2

媽呀,我怎麼會不記得這個解決方案的xD。謝謝! – Engo

+0

不是特別有效,因爲它必須組裝查詢,排序並返回第一行。 –

0
SELECT MAX(speed) as speed, time FROM info WHERE id = 1 AND time > 1234 ORDER BY id 

也許你試圖讓列中取壞。所以請嘗試給一個別名使用它作爲列名。

或者嘗試,因爲獲得最大的子查詢的條件值:

SELECT * FROM info WHERE id = 1 AND speed = (SELECT MAX(speed) FROM info) AND time>1234; 
+0

這個「as」是否有所作爲? – Engo

+0

@Engo你在哪裏檢查查詢的結果? –

+0

在數據庫(工作臺) – Engo

0
select id, speed, time 
    from info 
where speed = (select max(speed) 
        from info);