sql如下:
select log_type , device_type , soft_version , file_name
original_file_id , vehicle_model_id , upload_busi_type , key , object_key_info , project_id , file_type , happen_time ,
file_id FROM ( SELECT * , ROW_NUMBER() OVER (PARTITION BY key order by happen_time
desc) as row_num FROM VVMS_LOG.t_vvms_event_966100004
where key in ( 'key1' , 'key2' ) and device_type = 'VIU'
and data_start_time >= '2024-11-11 16:00:00.000' and '2024-11-13 15:59:59.999' >= data_end_time and project_id = '449259117547218944'
and happen_time
>= 1731340800000 and 1731513599999 >= happen_time
) as subquery WHERE 10 >= row_num ORDER BY vin
, happen_time
DESC LIMIT 10000;
问题说明: sql语义:子查询通过row_number 按照key分区, happen_time排序, 按照一定条件过滤后,输出row_num前10的数据; 问题:key2结果未返回,数据库中实际有key2数据,测试发现:key2满足条件的数据30w+, 表按照key分桶, happen_time分区(1天一个分区);缩短查询时间范围,可以都输出, 只查询key1或key2, 都可以正常输出, 同时查询只输出key1的结果