« first day (1538 days earlier)      last day (1120 days later) » 

2:12 PM
@haopei groupby is used when we want to sort based in the column namw
*on
 
 
3 hours later…
5:05 PM
@haopei When you want the "primary key" of your query to be more specific than the original result set
@haopei Say you're selecting many invoices, and you want to know the total per-customer. To get that, you have to make the query unique on customers, so you would GROUP BY invoice.customer_id
@haopei At that point, the only column you can safely reference is invoice.customer_id itself - any other columns have to be referenced through aggregate functions, such as SUM
So in this contrived example, you would get the invoice totals for each customer by running SELECT invoice.customer_id, SUM(invoice.total) FROM invoice GROUP BY invoice.customer_id
This works across multiple tables using JOINs. Just run the query without any GROUP BY to see what the result set would look like before your grouping/aggregate functions.
 

« first day (1538 days earlier)      last day (1120 days later) »