2014-02-23 148 views
0

我在我的数据库中有两个表。表up_to_date为每个记录指示特定页面(url)应该包含的评论数量(commentNumber)。表comment包含我在db中的实际注释以及相应的url。基于COUNT条件创建表格

CREATE TABLE up_to_date 
(id INTEGER PRIMARY KEY, 
url TEXT NOT NULL, 
commentNumber INTEGER) 

CREATE TABLE comment 
(id INTEGER PRIMARY KEY, 
commentMessage TEXT, 
url TEXT NOT NULL) 

我想创建一个表url_to_update用的,我需要更新网页的网址:记录在comment特定页面的数量比up_to_date.commentNumber什么表示在同一页小。

喜欢的东西

CREATE TABLE url_to_update AS 
(SELECT * FROM up_to_date 
WHERE up_to_date.commentNumber > COUNT(comment.url = up_to_date.url)) 
+0

什么RDBMS这是? –

回答

2

SQLite您可以创建一个表,这个语法create table Table_2 as select * from Table_1

CREATE TABLE url_to_update AS 
SELECT * FROM up_to_date 
WHERE up_to_date.commentNumber > (SELECT COUNT(comment.url) FROM comment 
WHERE comment.url= up_to_date.url); 

Here is a sample which you can see