Home > Blockchain >  Create table using multiple table
Create table using multiple table

Time:06-22

I'm trying to create a table from multiple tables.

table a has list of IDs and I need count of IDs stored in table C. enter image description here

Table b has list of IDs and need the count of them as well in table C. enter image description here

I'm trying below but getting an error:

Create or replace tablec as 

select 
Count(id) as total
from table a,
select count(ref) as ref_total
from table b

My desired output should look like below and should be filter applied by date.

enter image description here

CodePudding user response:

Consider using a subquery for each count like below.

CREATE OR REPLACE TABLE TableC AS
SELECT (SELECT COUNT(id) FROM TableA) AS total,
       (SELECT COUNT(ref) FROM TableB) AS ref_total
;

output:

enter image description here

But date range is something optional. For date range, I'm thinking to get whole data in new table then I can run select on table C

I think you can add date filter in WHERE clause of each subquery for your purpose.

  • Related