--한달이내 마지막 접속일 조회
select b.col1,count(1)
from table1 a
left join
table2 b
on a.col1 = b.col1
where b.last_date between current_date-1 * interval '30 day' and current_date+1* interval '1 day'
group by b.col1
order by col1
limit 30;
--특정기간 마지막 접속일 조회
select b.col1,count(1)
from table1 a
left join
table2 b
on a.col1 = b.col1
where b.last_date between
'2021-01-01 00:00:00' and '2021-01-01 00:00:00'
group by b.col1
order by col1
limit 30;
'IT > SQL' 카테고리의 다른 글
[mysql] insert select 구문 (0) | 2022.01.17 |
---|---|
[PostgrdSQL] WITH AS / CTE (0) | 2021.12.27 |
[PostgreSQL] 월별,시간별 데이터 집계 (0) | 2021.12.27 |
[PostgreSQL] [limit] 분할 삭제,분할 업데이트 (0) | 2021.12.27 |
[PostgreSQL] row_number() 행번호 (0) | 2021.12.27 |