天天看點

pg 時間查詢條件

時間查詢

select * from table 
where 1=1
and (  (''=${start_date} and ''=${end_date}) or 
	(''<>${start_date} and ''=${end_date} and to_char(sta_date,'yyyy-MM-dd')>=${start_date} ) or 
	(''=${start_date} and ''<>${end_date} and to_char(sta_date,'yyyy-MM-dd')<=${end_date} ) or 
	(''<>${start_date} and ''<>${end_date} and to_char(sta_date,'yyyy-MM-dd') between ${start_date} and ${end_date} ) 
)
           
pg