select * from student where studentNum is null;
select * from student where studentNum >4 limit 5;
随机抽取一条数据
select * from studen order by rand() limit 1;
GROUP BY的使用
group by的功能是让mysql知道在统计之前,如何对有关数据记录进行分类。如在count之前对sex进行分类。
select count(*) from student where sex='f';//女
select count(*) from student where sex='m';//男
等价于
select count(*) from student group by sex;
满足多个条件的子查询
select city,state,name from student
where (city,state)=
{
select city,state from other_table;
}
IN 和NOT IN
看其是否在这个集合中。
ALL ANY 和SOME
all代表多有,而any和some是同义词。
UNION
union的作用是把几个select语句放到一起,最终显示的结果也在一起。
例如
select StudentName from TABLE1 UNION select StudentName from TABLE2;
最终显示结果会把所有的结果都显示出来,但是注意,此处不显示重复的数据行。