2017-02-04 101 views
0

我的select語句查找記錄,我想更新 - 現在我要反轉(乘X -1)adjusted_sentiment得分只有這些記錄。下面是select語句:Sqlite-我有選擇,我如何更新這些記錄?

Select players.name, fbposts.company, fbposts.post_id, reactions.reaction, 
fbposts_comments.adjusted_sentiment, fbposts_comments.message, fbposts.message from fbposts 
join reactions on reactions.post_id = fbposts.post_id 
join players on players.id = reactions.id 
join fbposts_comments on fbposts_comments.post_id = fbposts.post_id 
where adjusted_sentiment > 0 and reactions.reaction like "ANGRY" and 
reactions.id = fbposts_comments.comment_id group by fbposts.post_id 

這將返回記錄等:

Baktiyar Romanov,WorldOfWanderlust,387990201279405_994067924004960,ANGRY,0.5965,probably fed very ill-mannered rich man 
Sheridan Toms,australiapost,96085205666_10153485650690667,ANGRY,0.04676666666666666,Seriously? You can't even get an express post parcel from victoria to wa in under 2 weeks!!!! Super annoyed 
Robert Smissen,australiapost,96085205666_10153487649895667,ANGRY,0.8555,Looks like Australia Post is using Diggers' letters to gain some reflected glory 
Eve Ismaiel,australiapost,96085205666_10153500759100667,ANGRY,0.1133333333333333,"Ha ha... Present $20, postage $30!!!" 

我想要做的就是反轉adjusted_sentiment得分。例如,在第一條記錄中,adjusted_sentiment得分爲0.5965,我想將其更新爲-0.5965

順便提一下,我的查詢和更新將通過Python2.7完成...我現在正在處理的一個想法是創建一個列表從上面的查詢中,然後使用該列表創建一系列更新語句。

回答

-1
Below query will give you the expected output 

update fbposts_comments set adjusted_sentiment = -adjusted_sentiment where post_id in (Select fbposts_comments.post_id from fbposts 
join reactions on reactions.post_id = fbposts.post_id 
join players on players.id = reactions.id 
join fbposts_comments on fbposts_comments.post_id = fbposts.post_id 
where adjusted_sentiment > 0 and reactions.reaction like "ANGRY" and 
reactions.id = fbposts_comments.comment_id group by fbposts.post_id) 
+0

這沒有奏效。我一直在閱讀,SQLite無法更新加入聲明。 –

+0

你可以分享你的樣品的sqlite文件 SQLite不支持更新加入,但我有一個嵌套子查詢上我運行更新查詢 –

+0

我覺得SQLite的分貝過大分享(350MB)和腳本來創建表是太長,無法進入註釋窗口。尋找到使用python腳本來解決...... –