2014-02-23 76 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