gpt4 book ai didi

mysql - 先添加近3天的订单记录(排除某些产品类型),然后按其他栏目排序

转载 作者:行者123 更新时间:2023-11-29 18:30:32 24 4
gpt4 key购买 nike

我有以下查询:

SELECT
prod.*,
details.specification,
details.warrantyinfo
FROM
Products prod
INNER JOIN ProductDetails details
ON details.product_id = prod.id
WHERE
prod.is_approved = '1'
AND prod.is_active = '1'
AND prod.is_deleted = '0'
ORDER BY
prod.created_at > '2017-08-14' DESC,
IF(prod.created_at > '2017-08-14', prod.created_at, FIELD(prod.listing_type,2,3,4,5,6)) DESC,
prod.is_featured DESC, prod.updated_at DESC
LIMIT 0, 20

这个查询实际上做的是 -

  1. 首先对最近三天添加的产品进行排序,
  2. 然后根据 listing_type 对产品进行排序
  3. 然后通过 is_featured

问题

这工作得很好,但在第一种排序条件下,如果 listing_type 为 2,我想排除产品。

谁能告诉我如何实现这个目标

SQLFIDDLE

http://sqlfiddle.com/#!9/9bb584/1

谢谢

最佳答案

对于那些将来遇到类似问题的人,

实际上将查询修改为这样。谢谢@Solarflare

SELECT
prod.*,
details.specification,
details.warrantyinfo
FROM
Products prod
INNER JOIN ProductDetails details
ON details.product_id = prod.id
WHERE
prod.is_approved = '1'
AND prod.is_active = '1'
AND prod.is_deleted = '0'
ORDER BY
prod.created_at > '2017-08-14' AND prod.`listing_type`>2 DESC,
IF(prod.created_at > '2017-08-14' AND prod.`listing_type`>2, prod.created_at, FIELD(prod.listing_type,2,3,4,5,6)) DESC,
prod.is_featured DESC

这完美地发挥了作用。

关于mysql - 先添加近3天的订单记录(排除某些产品类型),然后按其他栏目排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45727170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com