1. In SQL, we can use count in the query to get the number of a column in the table.

  query = "select count(birth_rate) from facts;"

2. Also, we can use AVG, SUM,MIN, MAX to get the different property of a column

  query = "select min(population_growth) from facts"

3. WE can also use mutiple aggregation function in a single query, and it will return mutiple tuples in a list

  query_mix = "select avg(population),sum(population),max(birth_rate) from facts"

4. We can use DISTINCT function to choose the unique element in a table.

  query = "select distinct birth_rate from facts"

5. Distinct can be combined with aggregate function.

  query = "select avg(distinct birth_rate) from facts where population > 20000000"

6. Column and column can do arithmetic in the query.  For arithmetic operation, float with float get float, float and integer get float, integer and integer get integer.

  query = "select population_growth/1000000.0 from facts" # The result is float

 

  

posted on 2016-11-18 15:27  阿难1020  阅读(100)  评论(0编辑  收藏  举报