0
Can you use GROUP BY without an aggregate function?
2 Respostas
+ 1
The GROUP BY clause is used in conjunction with the aggregate functions to group the result-set by one or more columns. e.g.:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
Remember this order:
1) SELECT (is used to select data from a database)
2) FROM (clause is used to list the tables)
3) WHERE (clause is used to filter records)
4) GROUP BY (clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns)
5) HAVING (clause is used in combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE)
6) ORDER BY (keyword is used to sort the result-set)
You can use all of these if you are using aggregate functions, and this is the order that they must be set, otherwise you can get an error.
Aggregate Functions are:
MIN returns the smallest value in a given column
SUM returns the sum of the numeric values in a given column
AVG returns the average value of a given column
COUNT returns the total number of values in a given column
COUNT(*) returns the number of rows in a table
0
Yes.