sql - SQLITE: Show total (sum) for each category -


i have 2 tables (inputs , categories):

create table categories (     iid integer not null primary key autoincrement,     sname text not null,     iparent integer,     foreign key (iparent) references categories(iid) );  create table inputs (     iid integer not null primary key autoincrement,     icategory integer,     dvalue double not null,     foreign key (icategory) references categories(iid) ); 

i need sums(dvalue column) inputs table each category. if sum result zero.

if possible better if sum each parent category ( when categories.iid = categories.iparent, summing results of child categories parent category )

can me? appreciate help! thanks!

try this:

select c.iparent, sum(i.dvalue) categories c left outer join inputs on i.icategory=c.iid group c.iparent 

edit : accounts:

select c.iparent, a.icurrency, sum(i.dvalue) categories c left outer join inputs on i.icategory=c.iid left outer join accounts on i.iaccount=a.iid group c.iparent,a.icurrency 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -