2habc

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

------------恢复内容开始------------

1.  
       SELECT device_id,gender,age,university 
       from user_profile 
       where age!=''"
或者
       SELECT device_id,gender,age,university 
       from user_profile 
       where age<>''"
或者
      SELECT device_id,gender,age,university 
      from user_profile 
      where age is not null
2.   where university = "北京大学" or university = "复旦大学" or university = "山东大学"
     等价于 where university in("北京大学" , "复旦大学" , "山东大学")
3.  where university like '%北京%'  
 
4.  查找gpa最高的

     select gpa
     from user_profile
     where university = '复旦大学'
    order by gpa DESC
    limit 1

    select max(gpa)
    from user_profile
    where university = '复旦大学'

5.   ROUND 函数用于把数值字段舍入为指定的小数位数。SQL ROUND() 语法

      SELECT ROUND(column_name,decimals) FROM table_name
           column_name 要舍入的字段

           decimals 要返回的小数位数

        

        select count(gender) as male_num,round (avg(gpa) , 1) as avg_gpa
        from user_profile
        where gender = 'male'

6.  聚合函数结果作为筛选条件时,不能用where,而是用having语法 

     select university,
     avg(question_cnt) as avg_question_cnt,
     avg(answer_cnt) as avg_answer_cnt
     from user_profile
     group by university
     having avg_question_cnt < 5 or avg_answer_cnt <20

7.  

      select device_id,question_id,result
      from question_practice_detail
      where device_id=(
      select device_id
      from user_profile
      where university='浙江大学'
     )
     order by question_id;

    select q.device_id,q.question_id,q.result
    from question_practice_detail q join user_profile u on q.device_id=u.device_id(两张表和在一起的条件)

    where u.university='浙江大学'
   order by q.question_id;

8.  union all不用去重

 

 

------------恢复内容结束------------

posted on 2022-05-06 16:47  哄哄2h  阅读(36)  评论(0)    收藏  举报