尝试多次订购表 [英] Attempting to order table multiple times
问题描述
我正在尝试对多行进行分组并按总值对其进行排序,但我一直在努力找出问题所在.
I am trying to group multiple rows and order it by the total values but im struggling to figure out whats going wrong.
Name Total
======= =======
ASOS 222
Tesco 11
ASOS 11111
Tesco 123
表格应如下图所示
Name Total
======= =======
ASOS 11111
ASOS 222
Tesco 123
Tesco 11
我认为此查询可以正常工作
I thought this query would work
select * from tablename order by name asc, total asc
但这显示结果顺序错误.
But that shows a result in the wrong order.
任何帮助将不胜感激.
推荐答案
尝试一下
select * from tablename order by total desc
如果您对ORDER BY语法不熟悉,则选择两件事对ORDER BY来说效果不佳.从您的描述来看,您似乎只希望最高的总数位于顶部.此查询将按总降序(最高的顺序)对结果进行排序
Selecting two things to ORDER BY doesn't work too well if you're not familiar with ORDER BY syntax. from your description, it looks like you just want the highest total at the top. This query will order the results by total descending (highest first)
如果您希望名称同时升序(从低到低),请尝试
if you want the names to be ascending (lowest first) at the same time, try
select * from tablename order by name asc, total desc
这篇关于尝试多次订购表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!