简体   繁体   English

为什么我的输出“Nama”没有升序 Mysql?

[英]why my output "Nama" didn't get Ascending Mysql?

please check this why the column "Nama" didn't get sorted请检查为什么“Nama”列没有排序

mysql> SELECT NIM, Nama
    -> FROM mahasiswa
    -> ORDER BY NIM, Nama;

the output输出

+----------+----------+
| NIM      | Nama     |
+----------+----------+
| 10296055 | Lia A    |
| 10296126 | Siti     |
| 10296130 | Deden A  |
| 10296135 | Ayu      |
| 10296140 | Didit K  |
| 10296145 | Yogi Adi |
| 10296187 | Andriana |
| 10296188 | Rafi     |
+----------+----------+
8 rows in set (0.00 sec)

only the "NIM" gets sorted by Ascending please help me只有“NIM”按升序排序,请帮助我

If you want to order on both the two columns, you need to add an order number to each of the two columns and match these two.如果要在两列上都订购,则需要在两列中的每一列中添加一个订单号并匹配这两个。 You can get the order for each column using the window function ROW_NUMBER :您可以使用窗口函数ROW_NUMBER获取每列的顺序:

SELECT t1.NIM, 
       t2.Nama 
FROM       (SELECT NIM,
                   ROW_NUMBER() OVER(ORDER BY NIM) AS ord
            FROM tab                                       ) t1
INNER JOIN (SELECT Nama,
                   ROW_NUMBER() OVER(ORDER BY Nama) AS ord
            FROM tab                                       ) t2
ON t1.ord = t2.ord

Check this SQL Fiddle .检查这个SQL Fiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM