strftime
사업이 찍은주의 :
SELECT count(*), count(*), date(date, '-'||strftime('%w',date)||' days') as date
FROM emails as m, contacts as me
WHERE datetime(date) > datetime('2010-08-25')
and datetime(date) < datetime('2011-08-25')
and (me.id = m.fr)
and me.email like '%gmail.com%'
GROUP BY date
ORDER BY date asc
업데이트는, 내가 대답을 발견했다. 그리고 여기에있는 동안 명시 적 조인 조건 (WHERE 절의 암시 적 조건이 아닌)으로 전환합니다. 당신이 비교를 포맷 어떤 주조 또는 필요가 없습니다
select count(*), count(*), m.date::date - extract(dow from m.date)::int as date
from emails as m join contacts as me on m.fr = me.id
where m.date > '2010-08-25'
and m.date < '2011-08-25'
and me.email like '%gmail.com%'
group by m.date
order by m.date asc
PostgreSQL은 그 자체 ISO8601 날짜 문자열와 타임 스탬프를 비교할 수 있습니다.
두 개의 count(*)
은 여전히 나에게 재미있어 보이지만 중복이 의미가있을 수 있도록 쿼리가 사용 된 컨텍스트를 알지 못합니다.
potsgres의 날짜 열에 어떤 유형을 사용하고 있습니까? –
실제로 두 개의'count (*)'가 있거나 오타가 있습니까? –
두 개의'count (*)'가있는 것 같습니다. 이유는 확실하지 않습니다. 날짜 유형은 "시간대가있는 시간 소인" – locoboy