1、获取指定时间前12小时数据
sql
SELECT
*
FROM
dispatch_team_real
WHERE
to_timestamp( start_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( to_timestamp( '2023-09-17 06:00:00', 'YYYY-MM-DD HH24:MI:SS' ) - INTERVAL '12 HOUR' )
AND to_timestamp( end_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( to_timestamp( '2023-09-17 18:00:00', 'YYYY-MM-DD HH24:MI:SS' ) - INTERVAL '12 HOUR' );
2、获取当前时间之前10s的数据
sql
SELECT
*
FROM
dispatch_team_real
WHERE
to_timestamp( start_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( now() - INTERVAL '10 seconds' ) ;
3、获取当前时间前10分钟的数据
sql
SELECT
*
FROM
dispatch_team_real
WHERE
to_timestamp( start_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( now() - INTERVAL '10 minutes' ) ;
4、获取当前时间前10天的数据
sql
SELECT
*
FROM
dispatch_team_real
WHERE
to_timestamp( start_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( now() - INTERVAL '10 days' ) ;
5、获取当前时间前10月的数据
sql
SELECT
*
FROM
dispatch_team_real
WHERE
to_timestamp( start_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( now() - INTERVAL '10 months' ) ;
6、获取当前时间前10年的数据
sql
SELECT
*
FROM
dispatch_team_real
WHERE
to_timestamp( start_time, 'YYYY-MM-DD HH24:MI:SS' ) = ( now() - INTERVAL '10 years' ) ;