我有一个PostgreSQL表,其中包含以下相关字段:
[FindsBy(How = How.Id, Using = "SomeID")]
public IWebElement SearchButton { get; set; }
可能有许多行包含相同的网址但标题不同。以下是一些示例行:
url
title
created_at
我试图获取列出以下字段的输出:
1)www.nytimes.com | The New York Times | 2016-01-01 00:00:00`
www.wsj.com | The Wall Street Journal | 2016-01-03 15:32:13`
www.nytimes.com | The New York Times Online | 2016-01-06 07:19:08`
2)url
对应于title
的最高值
3)该唯一created_at
title
的计数
因此,上面示例的输出行看起来像这样:
url
根据我在类似问题上阅读过的众多SO帖子,看来我获得前两个字段(www.nytimes.com | The New York Times Online | 2
www.wsj.com | The Wall Street Journal | 1
和最新url
)的最佳选择是使用{ {1}}:
title
同样,要获取第一个和第三个字段(DISTINCT ON
和所有select distinct on (url) url, title from headlines order by url, created_at desc
的计数),我只需使用url
:
title
我无法弄清楚如何结合上述方法并获得上述三个我想要获得的价值。
(编辑提供更多清晰度。)
答案 0 :(得分:5)
通过将query_string与SELECT
结合起来,可以在一个DISTINCT ON
内完成一次SELECT DISTINCT ON (url)
url, title, count(*) OVER (PARTITION BY url) AS ct
FROM headlines
ORDER BY url, created_at DESC NULLS LAST;
:
var mergedYaml
gulp.task('LoadYamlFiles', function() {
mergedYaml = global.mergedYaml;
try {
//Load all the Yaml files available inside pom folder
glob("tests/acceptance/wdio/utilities/pom/*.yml", function (er, files) {
mergedYaml = yamlMerge.mergeFiles(files);
})
}
catch (e){
console.log(e);
}
});
exports.mergedYaml = mergedYaml
相关(详细说明):
答案 1 :(得分:3)
尝试;
select t1.url, t2.title, t1.cnt
from (
select url, count(title) cnt
from headlines
group by url
) t1
join (
select distinct on (url) url, title
from headlines
order by url, created_at desc
) t2 on t1.url = t2.url
order by t1.url
join
url
答案 2 :(得分:1)