I have the following query from sqlite and would like to convert it to postgres:
select date(date, '-'||strfti开发者_如何学Cme('%w', date)||' days') as date from msgs group by date order by date asc limit 10;
update:
I believe this could do it: select (date::date - extract(dow from date)::int)::date as d from msgs group by d order by d asc limit 10;
That depends. Is it more important to group by date and then mangle the output to the format you want? Or are you better off grouping by date(date, '-'||strftime('%w', date)||' days')? If you wanna group by just date, then do something like
select date(x.date, '-'||strftime('%w', x.date)||' days') from (select date from msgs group by date order by date asc limit 10) as x;
Otherwise group by date(date, '-'||strftime('%w', date)||' days') and you're done.
精彩评论