-- 根据编号分组取第一条数据 select * from table t where t.no=(select max(no) from table t1 where t1.no=t.no) -- 根据编号分组后取第一条数据 SELECT * FROM (SELECT ROW_NUMBER() OVER (partition BY no ORDER BY no) rowId,* from table) t WHERE rowId=1
1.postgresql 查询每组第一个 ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC) 写法:SELECT ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC) AS 字段别名 FROM 表名: SELECT * FROM (SELECT *,ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC) AS
本次测试基与PostgreSQL 10.x版本 创建用户 [postgres@rtm2 data]$ /opt/pgsql-10/bin/createuser rentaomin [postgres@rtm2 data]$ 登陆psql查询创建的用户 postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------
Select EXTRACT(year from cast(joindate as timestamp)) as Year, EXTRACT(month from cast(joindate as timestamp)) as Month, EXTRACT(day from cast(joindate as timestamp)) as Day, ...... From Table Group by Year,Month,Day