i have been having for SQL trouble, i am using an SQLite database and can sadly not get the following to work. All help is appreciated.
I want the following query to sum all integers in the amount column of transactionTable fitting the criteria. One of the criteria changes from row to row in the outer query, so i want the inner query to run one time for every row in the outer query.
i get the following error when running this query: “no such column: ct.name”
i have bolded the line that i think is wrong in the query below.
table 1 : categoryTable
columns: id, icon, name, starred
table 2 : transactionTable
columns: id, date, amount, sign, category
query:
SELECT id, icon, name, starred, mySum
FROM categoryTable ct,
(SELECT sum(amount) AS mySum FROM transactionTable
WHERE date<'1992' AND date>'1990'
AND sign = '-' AND category=ct.name) AS sumTable
WHERE mySum!=0
ORDER BY mySum DESC
Thanks!
I think this can be done without the subquery. Try this version.