Could someone help me with this? I have couple of tables with some data. I need to query this table for the number of rows processed per day and load into another table:
Table1:
PNO ModelNo OrderNo CustID DAY
1 100012 1000AY 2345 31-AUG
2 109014 100YT8 3452 01-AUG
2 109014 100YT8 3452 31-AUG
Table2:
AN DAST CODE ROWS DAY
19 VEN EFD 19 31-AUG
21 EHT UYE 21 01-SEP
22 VEG WTE 24 01-SEP
Final Table:
DAY Source Rows
31-AUG Table1 2
01-SEP Table1 1
31-AUG Table2 1
01-SEP Table2 2
*Source: should be the table name.
Should I have to use Temp table or create a inner query concept and do it? Would like to know which is effecient. Please help.
Keep you updated: that all of these table are created under same schema..
As Shaharyar suggests, the reasons for actually creating such a table are probably questionable at best. However, the query to create the resulting table:
SELECT 'Table1' as Source, COUNT(*) as Rows, DAY FROM Table1 GROUP BY DAY
UNION
SELECT 'Table2' as Source, COUNT(*) as Rows, DAY FROM Table2 GROUP BY DAY
This doesn't scale very well for many tables. Though. Also, it would be preferable to add indexes on the DAY
columns.
If you actually want to generate a manifested table, this might do the job:
CREATE TABLE final_table SELECT ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.