Mysql练习

1)查询成绩表中name重复的

          select name from score group by name having count(*) > 1;

2)查询成绩表中name>2次,并且按照降序排列

         select count(name) as '出现次数',name from score group by name having count(name) > 2 order by '出现次数' DESC

3)去重

          select distinct name from score 

4)找出成绩大于150的,并且按照降序排列

         select * from score where  salary > 150 order by salary DESC

5)范围查找

      select * from 表名 where 字段名 [not] between 值1 and 值2;

       select * from score where  salary > 150  or (salary  < 100 and salary > 60) 

6)找出比平均成绩小的

       select * from score where salary < (select avg(salary) from score)

7)查询初年龄最小的学生姓名

       select name from score where age = (select min(age) from score)

8) 

        select e.name,e.department,e.salary, t.`平均成绩` from emp e,

       (select department,AVG(salary) as `平均成绩` from emp GROUP BY department) t

       where e.department = t.department and e.salary < `平均成绩`

                                                 

9)  

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值