在MySQL中的CASE,WHEN语句中,order by子句不起作用

时间:2015-07-29 12:46:58

标签: mysql

我正在尝试许多答案,但在查询下面会说" GET test/status/_search { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "test", "_type": "status", "_id": "1", "_score": 1, "_source": { "id": "1", "text": "Hello world", "language": "en" } } ] } } "。 但仍然无法弄清楚。请帮助排序 ORDER BY 问题

error in the query

2 个答案:

答案 0 :(得分:1)

从查询中删除第二个case

<强>查询

select m.feed_id,e.event_code,m.meeting_name,e.timestamp_updated,
e.event_time,m.country_code,m.category
from event e, meeting m 
WHERE m.id = e.meeting_id
AND m.date = '2015-07-29'
AND m.feed_id IN (1,2)
AND m.status ='A'  
AND e.off_time IS NOT NULL
AND e.settle_status = 'R'  
AND e.settle_status != 'V'  
ORDER BY
CASE WHEN  m.country_code = 'AU' THEN  e.timestamp_updated               
WHEN  m.country_code <> 'AU' THEN  e.event_code  
END DESC;

OR

select m.feed_id,e.event_code,m.meeting_name,e.timestamp_updated,
e.event_time,m.country_code,m.category
from event e, meeting m 
WHERE m.id = e.meeting_id
AND m.date = '2015-07-29'
AND m.feed_id IN (1,2)
AND m.status ='A'  
AND e.off_time IS NOT NULL
AND e.settle_status = 'R'  
AND e.settle_status != 'V'  
ORDER BY
CASE WHEN  m.country_code = 'AU' THEN  e.timestamp_updated               
ELSE e.event_code  
END DESC;

答案 1 :(得分:0)

您可以查看link。我的意思是也许你必须使用&#34; []&#34;其他情况?

相关问题