数据库(4)查询

来源:互联网 发布:最新机顶盒软件排行 编辑:程序博客网 时间:2024/06/05 13:23

基本语法

select * from 表名;

消除重复行

select distinct xxx from table;

条件

使用where子句对表中的数据筛选,结果为true的行会出现在结果集中

select * from 表名 where 条件;

比较运算符

等于=大于>大于等于>=小于<小于等于<=不等于!=或<>

查询编号大于3的学生

select * from students where id>3;

逻辑运算符

andornot

查询编号大于3的女同学

select * from students where id>3 and gender=0;

模糊查询

like%表示任意多个任意字符_表示一个任意字符

eg:
select * from students where sname like ‘黄%’ or sname like ‘%靖%’;

范围查询

1)不连续查询

select* from table where id in(1, 3, 8);

2)连续查询

select* from table where id between 1 and 9;

空判断

注意:null 与 ‘’是不同的
select * from table where xxx is null;

优先级

1)小括号,not,比较运算符,逻辑运算符
2)and比or先运算,

原创粉丝点击