Add columns in Oracle and merge two tables with different rows

Source: Internet
Author: User


In Oracle, how does one merge two tables with different columns and different rows into one? SQL: www.2cto.com select s. stagename sname, sum (nworkhours) nworkhours, sum (OVERHOURS) OVERHOURS, sum (nworkhours + OVERHOURS) from T_WorkDetails w, t_stage swhere w. stageid = s. stageid and w. projectid = 'd0927380468f4a4ee04010ac0c051f15 'group by s. stagenameORDER by s. stagename:

The second SQL statement is: select sum (total) as temptal from (select s. stagename sname, sum (nworkhours) nworkhours, sum (OVERHOURS) OVERHOURS, sum (nworkhours + OVERHOURS) totalfrom T_WorkDetails w, t_stage swhere w. stageid = s. stageid and w. projectid = 'd0927380468f4a4ee04010ac0c051f15 'group by s. stagenameORDER by s. stagename) is displayed as: www.2cto.com

The result to be displayed is:

Core Idea: select * from (Table A, Table B) the overall SQL statement is as follows: select * from (select s. stagename sname, sum (nworkhours) nworkhours, sum (OVERHOURS) OVERHOURS, sum (nworkhours + OVERHOURS) from T_WorkDetails w, t_stage swhere w. stageid = s. stageid and w. projectid = 'd0927380468f4a4ee04010ac0c051f15 'group by s. stagenameORDER by s. stagename) t1, (select sum (total) as temptal from (select s. stagename sname, sum (nworkhours) nworkhours, sum (OVERHOURS) OVERHOURS, sum (nworkhours + OVERHOURS) totalfrom T_WorkDetails w, t_stage swhere w. stageid = s. stageid and w. projectid = 'd0927380468f4a4ee04010ac0c051f15 'group by s. stagenameORDER by s. stagename) t2) Note: if the number of rows is small, the table automatically matches the table with the number of rows.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.