中易网

关于Sqlite使用Group by以后的排序问题。

答案:2  悬赏:0  
解决时间 2021-04-28 17:53
  • 提问者网友:唤魂
  • 2021-04-27 18:00
假如表是这样:
id column1 column2

有5行数据,他们的column2是一样的,所以我Group BY column2以后,就只有一行。那么结果剩下的这一行,我怎么决定究竟是第1行,还是第2行,还是第3行呢。。

谢谢。。
最佳答案
  • 二级知识专家网友:随心随缘不随便
  • 2021-04-27 19:11
这个你是不好决定是哪一行,因为这是分组,你如果是对column2进行分组,那也只能查询出column2,查询出的column不属于哪一行
全部回答
  • 1楼网友:猖狂的痴情人
  • 2021-04-27 20:47
$ sqlite3 sqlite version 3.7.13 2012-06-11 02:05:22 enter ".help" for instructions enter sql statements terminated with a ";" sqlite> create table tb_tmp (id int); sqlite> insert into tb_tmp values (1); sqlite> insert into tb_tmp values (2); sqlite> insert into tb_tmp values (3); sqlite> insert into tb_tmp values (4); sqlite> insert into tb_tmp values (5); sqlite> insert into tb_tmp values (6); sqlite> insert into tb_tmp values (7); sqlite> insert into tb_tmp values (8); sqlite> insert into tb_tmp values (9); sqlite> insert into tb_tmp values (10); sqlite> insert into tb_tmp values (11); sqlite> select * from tb_tmp; 1 2 3 4 5 6 7 8 9 10 11 sqlite> select * from tb_tmp order by id desc; 11 10 9 8 7 6 5 4 3 2 1 sqlite>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息