DQL基础查询/条件查询

基础查询:

  select name,age from stu;     -- 查两列

  select * from stu;        -- 查全部,不推荐

  select distinct address from stu;  --查一列去除重复数据

  select name,math as 数学成绩,english as 英语成绩 from stu;  -- 给列起别名

  select name,math 数学成绩,english 英语成绩 from stu;   --as可以省略

条件查询:

  大于/小于:

  select * from stu where age>20;    -- 大于20

  大于等于/小于等于:

  select * from stu where age>=20;    -- 大于等于20

  等于:

  select * from stu where age=20;    -- 等于20,注意是一个等号

  不等于:

  select * from stu where age!=20;      -- 不等于20

  select * from stu where age<>20;      -- 不等于20,<>和!=作用相同

  与:

  select * from stu where age>=20 && age<=30;  -- 大于等于20并且小于等于30

  select * from stu where age>=20 and age<=30;  -- &&与and作用一样

    特例:between ...and...:

    select * from stu where age between 20 and 30;     -- between...and...与&&与and作用一样

  或:

  select *from stu where age=10 or age=20 or age=30;

    特例:in

    select *from stu where age in (10,20,30)

  null:

  select *from stu where english is null;  -- 查空数据

  select *from stu where english is not null;  -- 查不为空的数据

  

posted @   大灰狼21  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示