where子句:前过滤 放在group by前边
例子1:where 配合 等值查询
查询city 表中 中国城市信息
select * from world.city where countrycode='CHN'; 从 world库的city表中 查询 关于 CHN 的
查询city 表中 美国城市信息
select * from world.city where countrycode='USA'; 从 world库的city表中 查询 关于 USA 的
例子2:where 配合 不等值查询< > <= >= <>
查询世界人口小于100人的城市
select * from world.city where population<100; 从 world库的city表中 查询 关于 人口<100 的
查询世界人口大于10000000人的城市
select * from world.city where population>10000000; 从 world库的city表中 查询 关于 人口>10000000 的
例子2:where 配合 模糊查询(like)
查询国家代号是C的城市
select * from world.city where countrycode like 'C%';
注意!!! like语句中 不要出现%在前面的情况 因为效率很低 不走索引
例子3:where 配合 逻辑连接符查询(AND OR)
查询城市人口1万 到 2万之间的
select * from world.city where population > 10000 and population < 20000;
从 world库的city表中 查询 关于 10000<人口< 20000 的
查询中国 或 美国的城市信息
select *
from world.city
where countrycode='CHN' or countrycode='USA';
select * from world.city where countrycode in ('CHN','USA');
建议吧以上两种 改写为下边的这种 因为这样效率比较快
select * from world.city where countrycode='CHN'
union [all]
select * from world.city where countrycode='USA';
网友评论