1

我的目的:

选择条目,has_t "1"只要它在那里,如果它不在那里,选择条目has_t "2"。相关访问的所有剩余条目应进入“more_items”列

问题:

当前代码首先选择has_t "2", 而不是has_t "1"

SELECT iu.*,`t`.`o_id`,
v.GID,v.MSID,
GROUP_CONCAT(DISTINCT CONCAT(iu.item_no,'|##|',t.s_amount,'|##|',t.e_item_ordered,'|##|',IFNULL(t.e_item_name,'No-Name-In-T-TBL'),'|##|',IFNULL(t.com,''),'|##|',IFNULL(t.post_s_e,''),'|##|',IFNULL(t.o_id,'')) SEPARATOR '|#|') AS MoreItems,
t.post_s_e,t.e_item_name,t.click_time
FROM `items_unique` iu
LEFT JOIN visits v ON v.id = iu.visit_id
LEFT JOIN trans t ON t.visit_id = iu.visit_id AND t.e_item_ordered = iu.e_item_ordered
WHERE iu.product_id = $PID AND has_t > 0 AND (t.com >= 10 OR has_t = 1)
GROUP BY `v`.`id` ORDER BY v.visited_at DESC LIMIT 10

注意:以前的代码版本似乎是使用不兼容的 SQL 子查询顺序完成的,这在 MariaDB 上无论如何都不起作用:

ORDER BY `iu`.`has_t` LIMIT 18446744073709551615
4

0 回答 0