100%-я база данных HSQL в оперативной памяти

Рассчитайте количество для каждой таблицы и объедините их, используя 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
6
задан Azim 10 July 2016 в 10:10
поделиться

1 ответ

Без проблем, просто откройте соединение с базой данных таким образом:

 Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:aname", "sa", "");

Для получения дополнительной информации обратитесь к документам HSQL.

7
ответ дан 17 December 2019 в 00:16
поделиться
Другие вопросы по тегам:

Похожие вопросы: