我正在尝试通过以下查询检索数据:
SELECT DISTINCT
o.id_order AS ID,
c.name AS ID_Carrier,
sl.name AS Store_Location,
o.date_add AS Order_date,
CASE WHEN h.id_order_state='2' THEN h.date_add END AS PAYMENT_VALIDATED,
CASE WHEN h.id_order_state='3' THEN h.date_add END AS IN_PROGRESS,
CASE WHEN h.id_order_state='160' THEN h.date_add END AS AWAITING,
CASE WHEN h.id_order_state='161' THEN h.date_add END AS SHIPPED,
CASE WHEN h.id_order_state='162' THEN h.date_add END AS READY_TO_COLLECT,
CASE WHEN h.id_order_state='84' THEN h.date_add END AS COLLECTED
FROM de_order_history h
LEFT JOIN de_orders o ON (o.id_order=h.id_order)
LEFT JOIN de_carrier c ON (o.id_carrier=c.id_carrier)
LEFT JOIN de_clickandcollect fs ON (o.id_order = fs.id_order)
LEFT JOIN de_store s ON (fs.id_store=s.id_store)
LEFT JOIN de_store_lang sl ON (sl.id_store=s.id_store)
WHERE sl.name = "XXX"
AND o.date_add >= "2019-02-12 00:00:01"
AND o.date_add <= "2019-02-12 23:59:59"
上面的查询返回的是有效数据,但我想将其转换为特定顺序的一行。目前,我相信由于在同一id_order的de_order_history中创建了多个记录,
我在下面收到:
由于这些记录来自相同的id_order,因此我想将其分成一行。
我尝试了以下方法:
MAX(CASE WHEN h.id_order_state='2' THEN h.date_add END) AS 01_PAYMENT_VALIDATED
不幸的是,由于“ END”,Prestashop 1.7返回错误。我对此事也感到困惑。
有什么办法可以实现我的目标?
谢谢。
答案 0 :(得分:0)
在请求中尝试使用group by
吗?
致谢