Cross SQL statement writing in Oracle

xiaoxiao2021-03-06  44

Example Description Data Sheet Structure (Red is the primary key) ==> Master table: test_part_cost_tab (material number information table) part_no varchar2 (20) part_name varchar2 (50) from table: test_part_cost_dt_tab (Medical Cost Data Sheet) Part_no varcha2 (10) COST_ID VARCHAR2 (5) COST NUMBER data ==> NAME 1 1000 Name1000 2 1001 Name1001 From Table Information: Part_no Cost_id Cost1 1000 100 1.1 2 1000 200 1.2 3 1000 300 1.34 1000 321 1.321 5 1001 100 2.1 Cross Data == > SQL statement generated result part_no part_name cost_100 cost_200 cost_300 cost_3211 1000 Name1000 1.1 1.2 1.3 1.3212 1001 Name1001 2.3 0 0 0 Specific cross SQL statement writing: select a.part_no, a.part_name, - sum (b.cost) SUM Case when b.cost_id = '100' TEN B.COST ELSE 0 END) AS COST_100, SUM (Case When B.COST_ID = '200' TEN B.COST ELSE 0 END) AS COST_200, SUM (Case When B.cost_ID = '300' Ten B.cost Else 0 End) AS COST_300, SUM (Case When B.COST_ID = '321' TEN B.COST ELSE 0 END) AS COST_321 from test_part_cost_tab A, test_part_cost_dt_tab bwhere a.part_no = b.part_nogroup by a.part_no, a.part_name ps: If the main table is available, from the table no information When crossing, there is no corresponding information solution in the WHERE condition. WHERE A.PART_NO = B.Part_no ( )

转载请注明原文地址:https://www.9cbs.com/read-54310.html

New Post(0)