查询语句(select)

查询语句(select)

用法:select 查询字段名 from 表名 [where 判断] [group by 分组字段] [having 分组字段进行运算] [order by 排序字段 desc|asc];

1.查询表中所有信息
    select * from users;
2.查询 姓名 和 id
    select name,id from users;
3.过滤表中重复数据。
    select distinct id from users;
4.使用where子句,进行过滤查询。
    select * from users where name='zs';    //查询 姓名 为 'zs' 的所有信息
    select * from users whers salary>15000; //查询 工资(salary) 大于15000 的人的信息
    select * from users where chinese+math+english>265; //查询总分大于265分的所有同学
    select * from users whers salary>15000 and salary<20000; //查询 工资(salary) 大于15000 小于20000 的人的信息
        select * from users where salary between 15000 and 20000;//这个效果和上面一样 但是小数据必须在前面
    select * from users where salary in(9200,9300,9500);   //查询 工资(salary) 在 9200,9300,9500 的人的信息
    select * from users where name like '胡%';   //模糊查询 查询所有姓  胡  的人的信息  % 匹配任何数目的字符,甚至包括零字符  _ 只能匹配一种字符 
    where还有很多的条件运算符 就不在此列举了,其实是自己不想找了
5.函数的使用
    select count(*) from users; //查询表中有多少条数据
    select sum(salary) from users; //计算本公司本月要支出多少工资
    select max(salary)|min(salary) from users; //最高工资 和 最低工资
6.group by 分组使用 配合其他语句使用
    select product,sum(price) from orders group by product; //对订单表中商品归类后,显示每一类商品的总价
            图片————————————————————————————————————————
7.having    
    select product,sum(price) from orders group by product having sum(price)>100;   //查询购买了几类商品,并且每类总价大于100的商品  
8.limit 查询第几条
select * from 表明 limit 起始位置,条数;

对select 语句的关键字 小结:

书写顺序: s…f….w….g….h….o

解析顺序: f…w….g….h….s….o

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值