Home > Back-end >  How to separate everything inside my sqlite database
How to separate everything inside my sqlite database

Time:08-13

i have a database which has two thing in my database, name of a fruit and how long is it in the freezer.

when i use

cur1.execute("""SELECT fruit_name, freeze_time,
                        COUNT (*) AS total_fruit
                        FROM fruit_page
                        GROUP BY fruit_name, freeze_days""")

rows = cur1.fetchall()

rows will actually show the name of the fruit, time in freezer and the amount of fruit in batch

[('Apple', '2', 2)('Banana','1',2)('Banana','2',1)]

How do i separate this, so that

[('Apple', '2', 1)('Apple', '2', 1)('Banana','1',1)('Banana','1',1)('Banana','2',1)]

Or at least tell me how do i make a list that can contain two same integer in it so when i have 2 piece of apple that is two days in freezer, when i call

for i in range(len(rows))
   if fruit_name == apple;
      basket.append(rows[i][1)

it will print actually print [2, 2] not just 2

CodePudding user response:

What you want is all the rows of the table with the columns fruit_name and freeze_time and a 3d column with the value 1:

SELECT fruit_name, 
       freeze_time, 
       1 AS columnname -- change the alias of this column
FROM fruit_page
  • Related