Reputation: 15
I have a table shown below
Id | Retweet_count | Fav_count |
---|---|---|
1 | 5 | 8 |
2 | 3 | 3 |
3 | 4 | 1 |
4 | 0 | 1 |
How do i create a new column in the table called "Total_interaction", where it shows the values of the sum of both Retweet_count and Fav_count like this.
Id | Retweet_count | Fav_count | Total_interaction |
---|---|---|---|
1 | 5 | 8 | 13 |
2 | 3 | 3 | 6 |
3 | 4 | 1 | 5 |
4 | 0 | 1 | 1 |
Currently i have my connection to my database as shown below.
import sqlite3
conn = sqlite3.connect('tweets_data.sqlite')
cur = conn.cursor()
Upvotes: 0
Views: 389
Reputation: 640
If you want to create a new column with the already present columns then you can use generated columns.
ALTER TABLE your_table_name
ADD Total_interaction INTEGER GENERATED ALWAYS
AS (Retweet_count + Fav_count);
Replace your_table_name with your Table name. You can read more about it here
Upvotes: 1