查询语句的postgreSQL问题

时间:2017-11-28 20:18:22

标签: postgresql

我正在学习postgreSQL,而且我对大多数人来说可能是一个非常基本的问题。我已经查看了很多不同的方法来使这个查询工作,但它不会根据我需要完成的工作。请注意,这不是一个家庭作业问题,而是来自不同的资源。问题是,有史以来最受欢迎的三篇文章是什么?哪些文章访问最多?将此信息显示为排序列表,其中最受欢迎的文章位于顶部。我到目前为止尝试过的查询语句是

news=> select articles.title, count(log.path) as art_view from log,
articles group by articles.title;
           title                | art_view
------------------------------------+----------
Bears love berries, alleges bear   |  1677735
Bad things gone, say good people   |  1677735
Balloon goons doomed               |  1677735
Trouble for troubled troublemakers |  1677735
There are a lot of bears           |  1677735
Media obsessed with bears          |  1677735
Candidate is jerk, alleges rival   |  1677735
Goats eat Google's lawn            |  1677735
(8 rows)

news=> select articles.title, count(log.path) as art_view from log, 
articles where status != '404 NOT FOUND' group by articles.title;
           title                | art_view
------------------------------------+----------
Bears love berries, alleges bear   |  1664827
Bad things gone, say good people   |  1664827
Balloon goons doomed               |  1664827
Trouble for troubled troublemakers |  1664827
There are a lot of bears           |  1664827
Media obsessed with bears          |  1664827
Candidate is jerk, alleges rival   |  1664827
Goats eat Google's lawn            |  1664827
(8 rows)

news=> select articles.title, count(log.path) as art_view from articles, 
log where status != '404 NOT FOUND' group by title;
           title                | art_view
------------------------------------+----------
Bears love berries, alleges bear   |  1664827
Bad things gone, say good people   |  1664827
Balloon goons doomed               |  1664827
Trouble for troubled troublemakers |  1664827
There are a lot of bears           |  1664827
Media obsessed with bears          |  1664827
Candidate is jerk, alleges rival   |  1664827
Goats eat Google's lawn            |  1664827
(8 rows)

news=> select articles.title, count(log.path) as art_view from articles 
join log on log.path where status !='404 NOT FOUND' group by title;
ERROR:  argument of JOIN/ON must be type boolean, not type text
LINE 1: ...t(log.path) as art_view from articles join log on log.path 
w...
                                                         ^
news=> select articles.title, count(log.path) as art_view from articles 
join log on substr(log.path) where status !='404 NOT FOUND' group by   
title;
ERROR:  function substr(text) does not exist
LINE 1: ...t(log.path) as art_view from articles join log on 
substr(log...
                                                         ^
HINT:  No function matches the given name and argument types. You might 
need to add explicit type casts.
news=>

感谢您的帮助。

0 个答案:

没有答案