SQL commonly used functions (continuously updated)

One of the two uses of -- case is that there is nothing after the case. 
SELECT coursename, score, CASE WHEN score<60 THEN 'Failed' WHEN score>=60 AND score<80 THEN '及格' ELSE 'Excellent' END score1 FROM `code_score`

-- another case followed by the column name.
select
  case sex
  when '1' then 'male'
  when '2' then 'female'
  else 'eunuch' end
from my_user

                                                          ---------------2018-4-16 Monday 


 

-- Query the names of students with no failing grades. Subquery|distinct function. 
SELECT DISTINCT (`name`) FROM my_score WHERE `name` NOT IN (SELECT `name` FROM my_score WHERE score <60)

                                                                ---------------2018-4-16 Monday 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324486016&siteId=291194637