mysql 语句该如何写

mysql 语句该如何写,第1张

最好是拆开来使用,比如数据里面有1,2,3 你要查询 1,3

就写find_in_set('1',ids) and find_in_set('2',ids);

如果你只是查询2

就直接 where find_in_set('2',ids);

如果是完全要相等 就直接写等于啊,如果只是需要包含就用上面的、

select

  goods_name 产品名字,

  max(price) 价格,

  max(case rank_name when 'VIP1' then (case when user_price is null then discount*price/100 else user_price end) end) vip1价格,

  max(case rank_name when 'VIP2' then (case when user_price is null then discount*price/100 else user_price end) end) vip2价格,

  max(case rank_name when 'VIP3' then (case when user_price is null then discount*price/100 else user_price end) end) vip3价格

from member_price mp

left join goods gd on gd.goods_id = mp.goods_id

left join user_rank ur on ur.rank_id = mp.rank_id

group by goods_name

mysql不是很熟悉,所以写了个标准sql语法的。我记得mysql中group by的select可以不用跟聚合函数的,所以LZ大概可以把max()去掉,而mysql中好像有isnull,ifnull的函数,我不太了解,这里用case语句替代了,LZ可以自行替换。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7110457.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存