数据库 带条件查询 SQL

-- 1) 关系运算符 > < >= <= = !=
select * from student where sex='男'


-- 2) and  or  
select * from student where sex='男' and age>18; 
select * from student where sex='男' && age>18; 

-- 查询 tid=101号老师的学生 或者年龄>25
select * from student where tid=101 or age>25
select * from student where tid=101 || age>25

select * from student where age>=18 and age<=28
-- 3) between and   在1828之间
select * from student where age between 18 and 28

--  4) in  not in  在 某个范围内的  
select * from student where sid in (2,3,6);
-- 等价于
select * from student where sid=2 or sid=3 or sid=6

select * from student where sid not in (2,3,6);


update student set tid=null where sid=2

select * from student 

-- 5) is null  is not null查询出tid为null的学生
select * from student where tid is null

select * from student where tid is not null

-- 6) like  not like  查询 模糊查找

insert into student values(null,'张三',default,8767,null,101);

insert into student values(null,'张四',default,8989,null,102);

insert into student values(null,'小张三',default,89898,null,102);

select * from student

--  查询姓张的所有学生
-- % 通配符  匹配任意字符任意多个 包括0个
select * from student where sname like '张%'
-- 查询名字中带张的
select * from student where sname like '%张%'

-- 查询两个字的名字 第二个字为三的
-- _通配符 匹配一个任意字符  
select * from student where sname like '_三'

select * from student where sname not  like '_三'

-- 查询第二个字为张的
select * from student where sname like '_张%'

-- 查询最后一个字是三或者四的
select * from student where sname like '%三' or sname like  '%四'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值