SELECT *, CASE
WHEN paydatefinal IS NULL OR paydatefinal = '0000-00-00' THEN paydate
ELSE paydatefinal END AS `paydatefinColumn`
FROM
`ws_crm_comenzi`
WHERE
`sezonId` = '4'
AND `service_id` = '1'
AND `finished` = '1'
AND `paydatefinColumn`='2016-09-26'
ORDER BY `paydatefinColumn` DESC
如何从An Column(PayDATEFIN列)中创建一个AND,而不是在表中,该列不存在
最佳答案
由于生成的列相当长,并且不能在where子句中使用生成的列,所以最简单的方法可能是将整个列包装到另一个select中
SELECT * FROM (
SELECT *, CASE
WHEN paydatefinal IS NULL OR paydatefinal = '0000-00-00' THEN paydate
ELSE paydatefinal END AS `paydatefinColumn`
FROM
`ws_crm_comenzi`
WHERE
`sezonId` = '4'
AND `service_id` = '1'
AND `finished` = '1'
AND `paydatefinColumn`='2016-09-26'
ORDER BY `paydatefinColumn` DESC)
AS A WHERE paydatefinColumn = whatever
关于php - MySQL查询案例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39704420/