1. Problem
When using a GROUP BY clause every field in the SELECT list must be either:- One of the GROUP BY terms - in this example customer_city.
- An aggregate function - for example SUM or COUNT
- An expression based on the above
name
may not be used
on the SELECT line.
In a group by line each region shows up only once - however in a typical region such as Africa there are several different
name
values. WHich one should SQL pick?
Solutions
- Remove the offending field from the SELECT line
- Add the field to the GROUP BY clause
- Aggregate the offending field
Example
select count(customer_id),customer_city from customers group by customer_city;
No comments:
Post a Comment