博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL学习笔记7:基本查询
阅读量:6180 次
发布时间:2019-06-21

本文共 1739 字,大约阅读时间需要 5 分钟。

参考表:student

 

多字段查询
mysql> select id,name,birth from student;

 

所有字段查询
mysql> select * from student;

 

where指定查询
mysql> select * from student where id=901;mysql> select * from student where id>=904;mysql> select name from student where department='计算机系';

 

in指定集合查询
mysql> select * from student where birth in(1988,1990);mysql> select * from student where id in(903,906);

 

not in非范围查询
mysql> select * from student where birth not in(1990,1998);

 

between and指定范围查询
mysql> select * from student where birth between 1986 and 1988;

 

not between and不在指定范围的查询
mysql> select * from student where id not between 904 and 906;

 

like字符串匹配查询
mysql> select * from student where name like '_三';mysql> select * from student where name like '张三';mysql> select * from student where name like '张%';

 

not like不匹配查询
mysql> select * from student where name not like '张%';

 

null查询
mysql> select * from student where address is null;

 

and多条件查询
mysql> select * from student where name like '张%' and birth>1985;mysql> select * from student where name like '张%' and birth>1985 and id like '%3';

 

or多条件查询
mysql> select * from student where id=905 or birth=1988;mysql> select * from student where id=905 or birth=1988 or sex='女';

 

distinct查询结果不重复
mysql> select distinct sex from student;mysql> select distinct department from student;

 

order by查询结果排序
mysql> select * from student order by birth;mysql> select * from student order by birth asc;mysql> select * from student order by birth desc;

 

group by分组查询
mysql> select sex,group_concat(name) from student group by sex;mysql> select sex,count(name) from student group by sex;

 

正则表达式查询
mysql> select * from student where birth regexp '1988|1990';

 

limit限制查询结果数量
mysql> select * from student limit 2;mysql> select * from student limit 1,3;

 

 

转载地址:http://ykbda.baihongyu.com/

你可能感兴趣的文章
调用Interop.zkemkeeper.dll无法使用解决方案
查看>>
贪心算法(Greedy Algorithm)
查看>>
DuBrute 3.1
查看>>
python的编码问题总结
查看>>
体育类词汇
查看>>
"ORM"
查看>>
动态变更网页样式
查看>>
java编译过程中的bug
查看>>
查询时多个文本框怎样判断
查看>>
malloc分配的内存空间是连续的吗
查看>>
分享20个吸引眼球的高品质免费PSD网站模板
查看>>
利用memcached构建高性能的Web应用程序(转载)
查看>>
表设计避免使用保留字
查看>>
编程算法 - 翻转单词顺序 代码(C)
查看>>
SpiderMonkey-让你的C++程序支持JavaScript脚本
查看>>
2013 华为校招机试题
查看>>
Clr编写Insert Triggr
查看>>
泛型(一)
查看>>
sql读取xml
查看>>
CSDN博客的一些问题(友好的吐槽)--后记,有一点点改进
查看>>