Xcode, iphone, Sqlite, need a sign function for group by? -
i need sql sign
function group query group positive , negative amounts.
unfortunately sqlite doesn't include one.
can suggest workaround ? or how ad 1 work libsqlite3.dylib framework used in xcode ?
my query quite complicated
select fcid, sum(price), (select sum(price) tmp b ((b.due < a.due) or ((b.due = a.due) , (b.pid <= a.pid)))) accumulated_price tmp due >= '2011-01-25' , due < '2011-02-24' , price <> 0 group fcid order due, pid;
what i'm trying do, group on sign(price)
2 result , negative value , positive value. these represent total expenses , total income.
would have added these tags (but i'm not allowed create new ones libsqlite3.dylib libsqlite3)
don't know if it's best choice, can try:
select your_val > 0, sum(aggregated_value) your_table group your_val > 0;
this way, should have 0
0 or negative values , 1
positive values.
update: if fcid
field need sign for, can try:
select fcid > 0, sum(price), ( select sum(price) tmp b ((b.due < a.due) or ((b.due = a.due) , (b.pid <= a.pid))) ) accumulated_price tmp due >= '2011-01-25' , due < '2011-02-24' , price <> 0 group fcid > 0;
note order by
clause useless since grouping results anyway.
Comments
Post a Comment