Рассчитайте количество для каждой таблицы и объедините их, используя UNION ALL
select
product_id
,sales_date
-- combine the counts from both tables
,sum(sales_count)
,sum(receipt_count)
from
(
-- get the counts for the sales table
select
product_id
,sales_date
,count(*) as sales_count
-- UNION needs the same number of columns in both Select -> adding a dummy column
-- 1st Select determines the datatype
,cast(0 as int) as receipt_count
from sales
group by product_id, sales_date
UNION ALL
-- get the counts for the receipts table
select
product_id
,receipt_date
,0
,count(*)
from receipts
group by product_id, receipt_date
) as dt
group by product_id, receipt_date
Без проблем, просто откройте соединение с базой данных таким образом:
Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:aname", "sa", "");
Для получения дополнительной информации обратитесь к документам HSQL.