开发者

order by and group by mysql

开发者 https://www.devze.com 2022-12-15 19:31 出处:网络
tell some big, diff between order by and group by, like sort columns data=>order by group it by si开发者_运维百科milar data used for aggregation , order by could be used inside the grouped items ,

tell some big, diff between order by and group by,

like sort columns data=>order by

group it by si开发者_运维百科milar data used for aggregation , order by could be used inside the grouped items ,

please Tell 5 diff


The order by clause is used to order your data set. For example,

select *
    from customers
    order by customer_id asc

will give you a list of customers in order of customer id from lowest to highest.

The group by clause is used to aggregate your data. For example,

select customer_id, sum(sale_price), max(sale_price)
    from customers
    group by customer_id
    order by customer_id asc

will give you each customer along with their total sales and maximum sale, again ordered by customer id.

In other words, grouping allows you to combine multiple rows from the database into a single output row, based on some criteria, and select functions of those fields not involved in the grouping (minimum, maximum, total, average and so on).


group by groups data by one or more columns, and order by orders the data by one or more columns? i don't really get the question?

using group by is similar to select distinct in the aspect that only unique values for the given values will be returned. furthermore you can use aggregate functions to calculate e.g. the sum for each group.

what do you want to hear? tell me five differences between apples and oranges?

0

精彩评论

暂无评论...
验证码 换一张
取 消