Using distinct on a column and doing order by on another column gives an error

前端 未结 11 2185
渐次进展
渐次进展 2021-02-05 14:43

I have a table: abc_test with columns n_num, k_str.

This query doesnt work:

    select distinct(n_num) from abc_test order by(k_str)

B

11条回答
  •  你的背包
    2021-02-05 15:45

    The first query is impossible. Lets explain this by example. we have this test:

    n_num k_str
    2     a
    2     c
    1     b
    

    select distinct (n_num) from abc_test is

    2
    1
    

    Select n_num from abc_test order by k_str is

    2
    1
    2
    

    What do you want to return

    select distinct (n_num) from abc_test order by k_str?

    it should return only 1 and 2, but how to order them?

提交回复
热议问题