I have a table as below
我有一张桌子如下
Column 1 Column 2
A 10000
A 20000
B 10000
B 30000
C 20000
C 50000
How do I reverse the Column 2 values with grouping on Column 1 using SQL like below?
如何使用如下所示的SQL对第1列进行分组来反转第2列值?
A 20000
A 10000
B 30000
B 10000
C 50000
C 20000
1 个解决方案
#1
2
There is no notion of "order" in RDBMS tables, so "switching" the rows is meaningless. If you want the rows from your table presented in a certain order, just query it accordingly with an order by
clause:
在RDBMS表中没有“顺序”的概念,因此“切换”行是没有意义的。如果您希望表中的行按特定顺序显示,只需使用order by子句查询它:
SELECT a, b
FROM my_table
ORDER BY a ASC, b DESC
#1
2
There is no notion of "order" in RDBMS tables, so "switching" the rows is meaningless. If you want the rows from your table presented in a certain order, just query it accordingly with an order by
clause:
在RDBMS表中没有“顺序”的概念,因此“切换”行是没有意义的。如果您希望表中的行按特定顺序显示,只需使用order by子句查询它:
SELECT a, b
FROM my_table
ORDER BY a ASC, b DESC