
mysql问题 选出两个不同的条件进行合并 并且第一个条件和第二个条件进行排序
现在又一张goods表有字段goods_id,goods_name,shop_price现在的要求是选出shop_price>4000的按照倒序排shop_price<1...
现在又一张goods表 有字段goods_id,goods_name,shop_price 现在的要求是选出 shop_price>4000的按照倒序排 shop_price<1000的按照正序排。一个sql语句完成。就像union一样最后是一个合并的结果集
求给sql和思路。 展开
求给sql和思路。 展开
1个回答
2015-05-21
展开全部
SELECT goods_id,goods_name,-1*shop_price AS shop_price FROM (
select goods_id,goods_name,case when shop_price>4000 then shop_price ELSE -1*shop_price END AS shop_price
from goods
where shop_price>4000 or shop_price<1000
) t
ORDER BY shop_price DESC
select goods_id,goods_name,case when shop_price>4000 then shop_price ELSE -1*shop_price END AS shop_price
from goods
where shop_price>4000 or shop_price<1000
) t
ORDER BY shop_price DESC
追问
非常感谢 您好这样是可以了排序了,但是价格我还要用的,出现了负值怎么办。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |