使用“groupby”

iecba09b  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(119)

我的查询思想是基于 line_id 这也是基于 enter_num 以及 exit_num .
使用带有注解代码的查询可以为我提供1个唯一id所需的结果。我需要的是每个id 6个结果。这可能吗?
我知道 GROUP BY 用于消除重复项。但我想从每个人身上得到6个结果 line_ID .
代码:

select * 
from 
  db_dn_us_icmlb_db1_202001.linecounting_records
where 
  line_id > 1
  and create_time between '2020-05-29 12:00' and '2020-06-01 12:25'
  and enter_num > 3
  and exit_num > 3
group by 
  line_id 
order by 
  enter_num + exit_num desc

结果

Line_id  enter_num  Exit_num   Create_time        Update_time   
62       11         11         2020-06-01 08:55   2020-06-01 09:02   
88       4          15         2020-05-29 12:00   2020-05-29 12:07   
74       9          7          2020-05-29 12:00   2020-05-29 12:09   
76       9          7          2020-05-29 12:00   2020-05-29 12:08   
75       6          9          2020-05-29 12:00   2020-05-29 12:08

预期结果

Line_id  enter_num  Exit_num   Create_time        Update_time 
62       11         11         2020-06-01 08:55   2020-06-01 09:02   
62       4          15         2020-05-29 12:00   2020-05-29 12:07   
62       9          7          2020-05-29 12:00   2020-05-29 12:09   
62       9          7          2020-05-29 12:00   2020-05-29 12:08   
62       6          9          2020-05-29 12:00   2020-05-29 12:08
62       11         11         2020-06-01 08:55   2020-06-01 09:02   
72       4          15         2020-05-29 12:00   2020-05-29 12:07   
72       9          7          2020-05-29 12:00   2020-05-29 12:09

等等。主要的一点是我希望每个“行id”有更多的值

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题