我通过以下查询使用distinct来获取唯一性 1个查询 select distinct(bhk,size,perprice),bhk,size,price from project_units; 和Iarray_agg(size) as size from project_units where project_id = '12' and bhk is not null and not bhk = '1bhk' group
我正在从mysql迁移到Postgres,在mysql中,我只需要做一个简单的Group By。我在Postgres中使用了查询,但我不确定这是否是最有效的方法,只是看起来应该有更好的方法。我最终不得不在年和月列的组合上运行Distinct。year和month列是整数。SELECT distinct on (year::text || month::text) id, name, type, month, year WHERE type
我已经认识到,我可能不需要"group_by“,而是"distinct on”。我的postgres查询如下所示:from posts
order by topic_id我尝试过使用selects和columns的不同的group_by排列方式,也尝试过distinct => 1。如果/当返回一个结果时,它实际上不会保持唯一性。
问题:我有一个表,其中有几行代码相同但日期不同,我也有一个查询:问:我如何返回列中每段代码的最新日期,并将其限制为1,因为可能存在重复:所以它只返回ID 1和4。SELECT * FROM movies WHERE CODE IN ('action', 'comedy') DESC LIMIT 1谢谢。