To compare the two tables in Oracle database -
i have 2 table below:
table_1 customer order ---------------------- david pizza david cola jack milkshake michael pizza michael milkshake alan cola alan pizza table_2 customer order ---------------------- david pizza david cola jack milkshake michael pizza michael milkshake alan milkshake alan pizza
i have code (i wrote request instead of order):
t (select customer ,row_number() over(partition customer order "order" desc) order_no ,"order" ,count(*) over(partition customer) order_cnt table_1) select customer, order1, order2, order3, order_cnt "counts of orders" t pivot (max("order") order_no in(1 order1, 2 order2,as order3)) order customer;
it making this:
table_1 customer order1 order2 order3 counts of orders ----------------------------------------------------------- david pizza cola null 2 jack milkshake null null 1 michael pizza milkshake null 2 alan cola pizza null 2
i implemented code table_2 , making this:
customer order1 order2 order3 counts of orders ------------------------------------------------------------- david pizza cola null 2 jack milkshake null null 1 michael pizza milkshake null 2 alan milkshake pizza null 2
i want compare these tables. example: david ordered pizza , cola in table_1 , table_2. true.
but alan ordered cola, pizza in table_1 , milkshake, pizza in table_2 want see differences between table_1 , table_2.
i have code , tables seem table_1 , table_2. when wrote code, see orders in both table_1 , table_2.
but want see differences between them.
something this?
with t (select customer ,row_number() over(partition customer order "order" desc) order_no ,"order" ,count(*) over(partition customer) order_cnt table_1) select customer, order1, order2, order3, order_cnt "counts of orders" t pivot (max("order") order_no in(1 order1, 2 order2, 3 order3)) order customer;
here result:
custome order1 order2 order3 counts of orders ------- --------- --------- --------- ---------------- david pizza cola 2 jack milkshake 1 michael pizza milkshake 2 3 rows selected.
Comments
Post a Comment