나랑 물건이랑 거리에 따라서 4단계로 나누고


거리마다 최신 순으로 해서 긁어 오려고 하거든


select * from 거리 < 3km order by 날짜


select * from 거리 between 3km and 5km order by 날짜


select * from 거리 between 5km and 10km order by 날짜


select * from 거리 between 10km and 20km order by 날짜


이렇게 4가지 쿼리를 하나로 합쳐서 검색해 보내려고 하는데


width tier1 as (

select * from 거리 < 3km order by 날짜

), tier2 as (

select * from 거리 between 3km and 5km order by 날짜

)

...

consolidated as (

select * from tier1 union select * from tier2 union ...

)

select * from consolidated 


이렇게 sql 쿼리를 짰는데. 


일단 문제가 다 합쳐져서 나와서 결과물이 거리 단계별도 아니고 날짜 별도 아니야 


어떻게 해야할까?