這是因爲你不能在你的WHERE
和ORDER BY
子句中使用別名
所以,你將不得不做一些像
SELECT *, IF(c.status = '1', "green", "red") AS colour
FROM (
SELECT *,'calls1' AS 'tbl', id AS cid FROM calls1
WHERE uid LIKE '%1111%'
ORDER BY timestamp DESC
UNION
SELECT *,'calls2' AS 'tbl', id AS cid FROM calls2
WHERE uid LIKE '%1111%'
ORDER BY timestamp DESC
) as c
LEFT JOIN objects AS o ON o.call_id = c.id
WHERE c.status = 'the color id you want' // or you can rewrite your if here
ORDER BY c.status ASC, c.timestamp DESC
或者,這爲您簡化查詢
SELECT *, "red" AS colour
FROM (
SELECT *,'calls' AS 'tbl', id AS cid FROM calls) as c
WHERE c.status = 'the color id you want'
ORDER BY c.created_date DESC
爲什麼按顏色分類,如果它總是紅色?
我認爲你需要'WHERE status ='2'' –
我更新了你的新查詢的答案 – Marc
我把IF語句拿出來了,仍然沒有運氣。 – hawx