码迷,mamicode.com
首页 > 其他好文 > 详细

Working with Data Sources 6

时间:2016-11-19 08:01:13      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:having   get   with   from   query   change   val   tab   table   

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

 

Working with Data Sources 6

标签:having   get   with   from   query   change   val   tab   table   

原文地址:http://www.cnblogs.com/kingoscar/p/6079799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!