This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
dev:sql:statements:select:group_by [2010/07/03 23:57] tdo |
dev:sql:statements:select:group_by [2016/06/28 22:38] (current) |
||
|---|---|---|---|
| Line 6: | Line 6: | ||
| ===== Description ===== | ===== Description ===== | ||
| - | |||
| ===== Syntax ===== | ===== Syntax ===== | ||
| + | <code> | ||
| + | GROUP BY group_by_columns | ||
| + | [ HAVING [ left_operand operator subquery ] | ||
| + | [ left_operand IN (subquery) ] ] | ||
| + | </code> | ||
| - | Statement | ||
| - | |||
| - | ===== Discussion ===== | ||
| - | |||
| - | == arg1 == | ||
| - | |||
| - | == arg2 == | ||
| ===== Examples ===== | ===== Examples ===== | ||
| Column Names From the Select List | Column Names From the Select List | ||
| - | select customer_no, sum(amount) from orders group by customer_no | + | select customer_no, sum(amount) from orders group by customer_no |
| - | + | ||
| - | select city, state, count(distinct company) from customers group by city, state | + | |
| - | + | select city, state, count(distinct company) from customers group by city, state | |
| Column Names Not in the Select List | Column Names Not in the Select List | ||
| - | select status, sum(amount) from orders group by customer_no, status | + | select status, sum(amount) from orders group by customer_no, status |
| - | select count(company) from customers group by state | + | select count(company) from customers group by state |