简体   繁体   中英

Python / SQLite - How to select from all Columns and Sum multiple colums?

I try to Code a search (select) function for my SQLite Database. At the Moment i get a Keyword from a TextCtrl (simplified for short example here) and i try to search in every column of my SQLite Database.

keyword = "Product_1"

Better would be if i could also select with Multiple Keywords (list):

keywords = ["Product_1", "Category_2"]

How do I search in all columns?

c.execute('SELECT * FROM Test WHERE AnyColumns=?', (keyword,))

Later on i need to Sum two of my columns. At the Moment I do it like this:

c.execute("SELECT SUM(overall_cost) FROM vm WHERE id=5")
result = cur.fetchone()[0]
c.execute("SELECT SUM(overall_price) FROM vm WHERE id=5")
result2 = cur.fetchone()[0]

Is it possible to do this in one step? Something like SUM(overall_cost) and SUM(overall_price) ?

I need those two values seperate. Not summed up to one value!

是的可能

"SELECT SUM(overall_cost) as overall_cost,SUM(overall_price) as overall_price  FROM vm WHERE id=5"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM