Hi,

This works as well:

(select id, name, sum(amount) from one
where v_date between '2010-01-05' and '2010-01-06'
group by id, name
union
select id, name, sum(amount) from one
where v_date < '2010-01-05'
group by id,  name)
order by name;

The complete test case:

drop table one;

create table one(id int primary key,
v_date date, name varchar(20), amount int);

insert into one values(1, '2010-01-04', 'abcd', 400);
insert into one values(2, '2010-01-04', 'efgh', 400);
insert into one values(3, '2010-01-04', 'ijkl', 400);
insert into one values(4, '2010-01-05', 'abcd', 500);
insert into one values(5, '2010-01-05', 'efgh', 500);
insert into one values(6, '2010-01-05', 'ijkl', 500);
insert into one values(7, '2010-01-06', 'abcd', 600);
insert into one values(8, '2010-01-06', 'efgh', 600);
insert into one values(9, '2010-01-06', 'ijkl', 600);

(select id, name, sum(amount) from one
where v_date between '2010-01-05' and '2010-01-06'
group by id, name
union
select id, name, sum(amount) from one
where v_date < '2010-01-05'
group by id,  name)
order by name;

Regards,
Thomas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to