select 配合where子句

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';

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 上节重点难点回顾: 1. 数据类型 2. 列属性 primary key unique not null defa...
    张鑫泽_2109阅读 553评论 0 0
  • select 作用:获取MySQL中的数据行 单独使用select: select @@xxx 查询参数信...
    蔺蔺蔺赫赫阅读 462评论 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,974评论 0 10
  • 1、什么是数据库? 数据库是以数据结构的形式组织数据的,数据库是用户层面的,是由用户后来去实现的,用户可以对文件中...
    Jzyue阅读 340评论 0 1
  • 我是在高考完之后才开始接触古风歌曲的,起初是在酷狗上听了几首歌,感觉还不错,后来经同学安利,转战网易云音乐,此后便...
    清笛渐响6阅读 4,183评论 1 4

友情链接更多精彩内容