1. GROUP BY function

  The group by function will categroy the table according to different requirement:

  Select Employed, Major_category, SUM(Employed) FROM recent_grads GROUP BY Major_category; #Here, in the table, the program first group by Employed and Major_category. Then they use aggregate function to get the result.

2. If we would like to change name of each column in the query result, we can use AS function:

  Select sum(Men) as total_men, sum(Women) as total_women from recent_grads;

3. When we use AS, we choose HAVING instead of WHERE:

  Select Major_category, Avg(low_wage_jobs)/ Avg(Total) as share_low_wage from recent_grads group by Major_category having share_low_wage > 0.1;   

4. We use ROUND function to round values when query them:

  SELECT Major_category, ROUND(ShareWomen, 2) AS rounded_share_women 

  FROM recent_grads;  # Round the ShareWomen column to 2 decimal places

 

posted on 2016-11-19 07:13  阿难1020  阅读(130)  评论(0编辑  收藏  举报