有点有难度的SQL语句 还是初学者
发布网友
发布时间:2022-05-09 19:36
我来回答
共5个回答
热心网友
时间:2023-10-15 13:52
select a.*,b.machine_ip,b.district_id from
(select active_rfid_code,min(command_time) as first_command_time, from table1 group by active_rfid_code where district_id ='中国') a left join table1 b on a.active_rfid_code=b.active_rfid_code and a.first_command_time=b.command_time
加上distinct是纯粹画蛇添足
热心网友
时间:2023-10-15 13:52
select active_rfid_code,command_time ,machine_ip,district_id
from table1 where command_time in (select min(command_time) from table1 group by active_rfid_code)
热心网友
时间:2023-10-15 13:52
回答者llq520 你的答案不是我想要的阿。
回答者kimipolo 你的答案不好用的阿。
热心网友
时间:2023-10-15 13:53
Oracle 表示
select table1.* from
table1,
(
select active_rfid_code, Min( To_number( to_char(command_time,'yyyymmdd') ) ) as Mt
from table1 group by active_rfid_code
) tabel2
wehre table2.active_rfid_code = table1.active_rfid_code(+)
热心网友
时间:2023-10-15 13:54
这句应该可以实现你要的:
select distinct * from table1 as A where (select min(command_time) from table1 as B where a.district_id=b.district_id )=command_time