gpt4 book ai didi

mySQL 按参数排序

转载 作者:行者123 更新时间:2023-11-29 15:37:43 26 4
gpt4 key购买 nike

有一个sql请求:

SELECT
`e` .*,
`cat_index`.`position` AS `cat_index_position`,
`price_index`.`price`,
`price_index`.`tax_class_id`,
`price_index`.`final_price`,
IF(price_index.tier_price IS NOT NULL,
LEAST(price_index.min_price, price_index.tier_price),
price_index.min_price) AS `minimal_price`,
`price_index`.`min_price`,
`price_index`.`max_price`,
`price_index`.`tier_price`
FROM
`catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index_store2` AS `cat_index` ON
cat_index.product_id = e.entity_id
AND cat_index.store_id = '2'
AND cat_index.visibility IN(2,4)
AND cat_index.category_id = '153'
INNER JOIN `catalog_product_index_price` AS `price_index` ON
price_index.entity_id = e.entity_id
AND price_index.website_id = '3'
AND price_index.customer_group_id = '1'
WHERE
((`e`.`sku` IN('96005', '5806', '96004','PROD91','PROD187')))
AND (e.created_in <= '1548056609')
AND (e.updated_in > '1548056609')

我得到这个结果:

enter image description here

但我需要像 IN 内那样按顺序排列:96005','5806','96004','PROD91','PROD187'

最佳答案

使用“case”语句例如:

SELECT * FROM 
...
ORDER BY case when <your_value> = '96005' then 1
when <your_value> = '5806' then 2
when <your_value> = '96004' then 3
when <your_value> = 'PROD91' then 4
when <your_value> = 'PROD187' then 5

关于mySQL 按参数排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58062285/

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