小编Ran*_*Joe的帖子

具有最大和最小日期以及每行关联 ID 的 PostgreSQL 查询

我有下表:

CREATE TABLE trans (
    id SERIAL PRIMARY KEY,
    trans_date date,
    trans_time time        
);
Run Code Online (Sandbox Code Playgroud)

我想有以下观点

CREATE OR REPLACE VIEW daily_trans AS
SELECT trans_date,
    max(trans_time) as first, 
    min(trans_time) as last,
    calculate_status(min(trans_time), max(trans_time)) as status 
GROUP BY trans_date 
Run Code Online (Sandbox Code Playgroud)

带有指定最大和最小 trans_time id 的列。

我怎么做?

postgresql aggregate window-functions

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

aggregate ×1

postgresql ×1

window-functions ×1