sql常用问题(一)

一、sql要掌握

      1、sum

          select  sum(score) from table

      2、group

            select name, sum(score) from table group by 

      3、avg()

           SELECT AVG(OrderPrice) AS OrderAverage FROM Orders

 

一、查询是否存在

      1、查询数据是否存在

           SELECT COUNT(*) FROM Table_name WHERE ID=xxx;

     2、查找重复数据  

           select * from people where peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)

     3、查找表中多余的重复记录(多个字段)

         比如名字重复:

         select  name, count(name) as count from test_table group by name having count>1;

        例子:查下图重复的student_no, 输入:

          

            输入:select student_no, count(student_no) as count from score GROUP BY student_no having count>1;

            

    4、查询平均分大于80;字段(name、score1、score2)

       select name from test_table group by name having avg(score)>80

          例子,在以下两个表格找,平均分大于80的student name

                   

              运行:select student_name from student where student_no = ( 

                                      select student_no from score a GROUP BY student_no having AVG(score) > 80)

              

  5、查询三门课都大于80 的学生;

         SELECT S.name FROM Student S GROUP BY S.name Having MIN(S.score)>=80

 

  

 

         

  

转载于:https://www.cnblogs.com/Jomini/p/9438604.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值