mysql - mySQL按参数排序
问题描述
有一个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')
我得到了这个结果:
但我需要像 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
推荐阅读
- r - 关闭应用程序后保存对数据表所做的更改 (R)
- javascript - 在 JavaScript ES6 中,可迭代对象和迭代器有什么区别?
- java - 从活动中获取数据到 RecyclerView 适配器?
- c++ - 抛出异常:读取访问冲突。它是 0xFFFFFFFFFFFFFFFF
- vue.js - 如何在不使用 Vue 文件中的道具的情况下从模板中访问数据属性?
- erlang - 具体解码选择ASN.1
- visual-studio - 基于 docker 的 Visual Studio 构建 - 不起作用
- awk - 包含插入符号的 Awk 多字符字段分隔符未按预期工作
- php - 仅在给定列唯一的情况下生成数据以填充数据库
- iis - Consul 和 IIS 托管应用程序