有人可以幫助我將此sqlite查詢轉換爲postgres查詢嗎?將sqlite轉換爲postgres查詢
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
更新,我找到了答案:
select count(*), (m.date::date - extract(dow from m.date)::int) as dat
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 dat
order by dat
你在potsgres的日期欄中使用了什麼類型? –
真的有兩個'count(*)'還是一個錯字? –
似乎有兩個'count(*)',不知道爲什麼。日期類型是「帶時區的時間戳」 – locoboy