1. 程式人生 > 其它 >break以及continue語句

break以及continue語句

------------恢復內容開始------------

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不用去重

 

 

------------恢復內容結束------------