select * from test #查询表中全部数据
select * from voip.test #查询全部还可以这么写,voip表示为数据库名
select u_id,u_name from test #查询表中某一个或多个字段的数据值
select u_name as name from test #查询出结果字段以别的名称显示,但真实的字段结构不会变
select * from test where u_name="浩子" #查询u_name 字段等于浩子的所有数据
select * from test where u_name <> "浩子" #查询u_name 字段不等于浩子的所有值
select * from test where u_id in (1,2,5) #查询u_id 字段中包含1,2,5的数据
select * from test where u_id not in (1,2,5) # 查询u_id 字段中不包含1,2,5 的数据
select * from test where u_name like "%浩%" #查询u_name 字段中 匹配或包含有“浩”的数据
select * from test where u_id between 1 and 5 #查询u_id 字段中 第1条到第5条的数据
select * from test where u_id not between 1 and 5 #查询u_id 字段中 不是第1条到第5条的数据
select * from test where u_id >=1 #查询u_id字段中大于并且等于1的数据, 反之则是 <= 、>、< 都可以
select * from test where u_name="浩子" and remark="voip" # 查询u_name的值等于“浩子”并且 remark=“voip” 的共同条件
select * from test where u_name="浩子" and remark="voip" # 查询查询u_name的值等于“浩子” 或者 remark=“voip” 中的某一条件
select * from test group by remark #查询remark字段中不同的统称,打个比分说该字段中有学生N个,工人N个,那么查询出来的结果就学生和工人,而不会显示更多的学生和工人
select * from test order by regdate asc #查询regdate(日期)字段中正序排列,也就是说按最早日期排列
select * from test order by regdate desc #查询regdate(日期)字段中倒序排列,也就是说按最晚日期排列,通常应用在最新发表什么什么的排序
select * from test limit 0,3 # 查询表中前3条记录(下表从0开始) select * from test limit 3 这样写也OK
select count(*) from test #统计表中共有多少条记录 select count(u_id) from test 这里是统计某一字段共有的记录
select max(u_id) from test #查询u_id字段中最大值的数据,一般只能是对整型、数字这方面进行比对
select min(u_id) from test # 这个就。。。最小值。。。
select avg(u_id) from test #查询某一字段的平均值,一般用于查询某什么什么平均年龄或者工资什么的
select sum(u_id) from test #查询某一字段的累加值,一般用于查询该字段中共多少工资什么什么的