postgreSql 常用查询总结

1. 日期格式转化(参考

select beg_time, end_time, extract(epoch from to_timestamp(end_time,'yyyy-mm-dd-HH24-MI-SS-US'))-extract(epoch from to_timestamp(beg_time,'yyyy-mm-dd-HH24-MI-SS-US')) from cdb_all_iu_data where beg_time > '2017-09-21' 

注:beg_time, end_time以TEXT形式存储,求时间差时转化为时间戳再相减得到结果(s)

2. select * from (中间结果) t

select count(*) from (
select chkid, count(*) from abc_table GROUP BY chkid) t
原文地址:https://www.cnblogs.com/kaituorensheng/p/7588007.html