
你好 刚刚问你的Mysql在pgsql中遇到个问题 可以帮忙看下?
select*from(select*,concat(name,code)as__ffromtestorderbydatedesc)__tgroupby__f;在pgsq...
select * from (select *, concat(name,code) as __f from test order by date desc) __t group by __f;
在pgsql中报
错误: 字段 "__t.id" 必须出现在 GROUP BY 子句中或者在聚合函数中使用
LINE 1: select * from (select *, concat(name,code) as __f from tes...
^
********** 错误 **********
错误: 字段 "__t.id" 必须出现在 GROUP BY 子句中或者在聚合函数中使用
SQL 状态: 42803
字符:8
如果写成这样就行 可是不能去重复数据了
select __t.id from (select *, concat(name,code) as __f from test order by date desc) __t group by __t.id,__f;
上面的sql(select * from (select *, concat(name,code) as __f from test order by date desc) __t group by __f;
)在mysql运行没问题
表结构 & 数据
id date name code
1 2015-1-1 张三 1111
2 2015-2-1 李四 2222
3 2015-3-1 张三 1111
4 2015-4-1 王五 3333
5 2015-5-1 赵六 4444
根据字段name和code的值 如果两个值都相同的数据 就按date最大的保留
例如
id为1和3的 name和code都一样 就保留date最大即Id为3的这条数据 展开
在pgsql中报
错误: 字段 "__t.id" 必须出现在 GROUP BY 子句中或者在聚合函数中使用
LINE 1: select * from (select *, concat(name,code) as __f from tes...
^
********** 错误 **********
错误: 字段 "__t.id" 必须出现在 GROUP BY 子句中或者在聚合函数中使用
SQL 状态: 42803
字符:8
如果写成这样就行 可是不能去重复数据了
select __t.id from (select *, concat(name,code) as __f from test order by date desc) __t group by __t.id,__f;
上面的sql(select * from (select *, concat(name,code) as __f from test order by date desc) __t group by __f;
)在mysql运行没问题
表结构 & 数据
id date name code
1 2015-1-1 张三 1111
2 2015-2-1 李四 2222
3 2015-3-1 张三 1111
4 2015-4-1 王五 3333
5 2015-5-1 赵六 4444
根据字段name和code的值 如果两个值都相同的数据 就按date最大的保留
例如
id为1和3的 name和code都一样 就保留date最大即Id为3的这条数据 展开
2015-11-02 · 知道合伙人软件行家
关注

展开全部
PostgreSQL的话,用这个:
select * from test where id in (select max(id) from test group by concat(name,code));
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询