sql - Can I combine my two SQLite SELECT statements into one? -


I have a SQLite table called posts An example is given below. I would like to calculate monthly income and expenditure.

 accId Date Text Balance ---------- ---------- ------- ----------- ------ ---------- ---------- 2008-03-25 Ex1-64.9 3747.56 1 2008- 03-25 Shop2-91.85 3655.71 1 2008-03 -26 Benny's -100.0 3555.71 

I have this question for income:

 SELECT SUBSTR (date, 0, 7) "month", total (quantity) "income" posts From where the amount> 0 month order date by group; 

This works fine:

Monthly Income ---------- ---------- 2007-05 4877.0 2007-06 8750.5 2007- 07 8471.0 2007-08 5503.0

Now I need the expenses and I can repeat the first statement with the condition of its cause Amount & lt; 0 , but I'm thinking that a query is a great way to get both income and expenditure?

try something like this

  select substrold ( Date, 0,7) "Month", total (in case when a> 0 then another zero) "Income"  
Case "(when a & lt; 0 is again another zero)

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -