当前位置:   article > 正文

mysql 条件判断_mysql数据库sql查询语句:多条件判断

mysql中多条件判断客服会员等级

展开全部

1、创建测试表,

create table test_person(id int, RMB int);

0e0179bbd20743941ed3877b44ace78f.png

2、插入测试数据

insert into test_person values(1,180);

insert into test_person values(2,170);

insert into test_person values(3,290);

insert into test_person values(4,160);

insert into test_person values(5,299);

insert into test_person values(6,266);

insert into test_person values(7,155);

b2e01526862647f58fbe1593eac7c7f8.png

3、查询表中所有记录,select t.* from test_person t,

55b453864b04d515b1756bdeba34ee7a.png

4、编62616964757a686964616fe58685e5aeb931333431373862写sql,汇总每个vip类型的用户数,

select vip_type, count(distinct id)

from (select case when RMB>100 and RMB<200 then 'VIP1' when RMB>200 then 'VIP2' end as vip_type, id

from test_person) t

group by vip_type

53ce53c06364d99cd8d54a62aebbbe21.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/730174
推荐阅读
相关标签
  

闽ICP备14008679号