重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

mysql中怎么写判断,sql如何写判断

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

1、创建测试表,

创新互联专注于如东网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供如东营销型网站建设,如东网站制作、如东网页设计、如东网站官网定制、微信小程序开发服务,打造如东网络公司原创品牌,更为您提供如东网站排名全网营销落地服务。

create table test_person(id int, RMB int);

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);

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

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

select vip_type, count(distinct id)

from (select case when RMB100 and RMB200 then 'VIP1' when RMB200 then 'VIP2' end as vip_type, id

    from test_person) t

group by vip_type

mysql里面写判断语句怎么写

思路如下,分别将A与B,A与C进行关联,然后使用 union 进行连接,查询时,直接使用这个查询就可以了(可以建个视图,查询起来比较方便 ),如下:

select d.id, d.name

from (select A.id, B.name

from A, B

where A.id = B.id

and A.type = '教师'

union

select A.id, C.name

from A, C

where A.id = C.id

and A.type = '教室') d

where d.id = 123

有问题请追问,希望可以帮到你

mysql 怎么判断一个表中的某一列有没有某个值

1、mysql中创建测试表,create table test_user(id int, name varchar(20));

2、插入测试数据,

insert into test_user values(1001,'jack');

insert into test_user values(1002,'lucy');

insert into test_user values(1003,'mike');

insert into test_user values(1004,'john');

insert into test_user values(1005,'may');

3、查看表中所有数据,select * from test_user

4、编写sql,查询name列是否有jack名,

select * from test_user t where name = 'jack'


网站标题:mysql中怎么写判断,sql如何写判断
标题网址:http://cqcxhl.com/article/dscojdp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP