PostgreSQL:分组依据,具有日期间隔

时间:2014-04-04 21:50:32

标签: sql postgresql where intervals having

我尝试按拨打的号码和日期创建一个选择组。我使用PostgreSQL,但遗憾的是我无法获得满意的结果。 (抱歉我的英语不好,我使用谷歌翻译。) 我试图使用这个选择:

SELECT
    callerid,
    to_no,
    is_fromoutside,
    -- starttime::date,
    -- to_char(starttime,'DD-MM-YYYY'),
    -- starttime,
    count(to_no),
    count(starttime)
FROM    callhistory3
where
    starttime between '2014/03/21' and '2014/04/21'
group by
    callerid, to_no, from_no, is_fromoutside, starttime
having
    is_fromoutside='f'
and callerid like '9030'
and to_no not like '9%'
order by starttime desc
;

结果:

"9030";"00262733319999";f;"2014-04-03";1
"9030";"00262733319999";f;"2014-04-03";1
"9030";"002614996837199";f;"2014-03-28";1
"9030";"032280840";f;"2014-03-28";1
"9030";"020156128";f;"2014-03-25";1
"9030";"0989168482";f;"2014-03-25";1
"9030";"0987131781";f;"2014-03-25";1

0 个答案:

没有答案