Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, take a look at below query and at the results:</p> <pre><code>SELECT * FROM (SELECT cs.cd, cs.dsc, cp.part_cd, cp.qty, cp.dllrs, cp.cu_type FROM ck_startup cs JOIN ck_price cp ON (cs.prd_type_cd = cp.prd_type_cd)) PIVOT (SUM(dllrs) AS dlllrs FOR (cu_type) IN ('A' AS a, 'AC' AS ac)) ORDER BY cd, qty ; </code></pre> <p>Output:</p> <pre>CD DSC PART_CD QTY A_DLLLRS AC_DLLLRS -------- ----------------- ---------- ------- ---------- ---------- 3D Stuff 1 100 10 3D Stuff 1 200 20 3D Stuff 1 300 30 30 DC Different stuff 1 100 50 50 DC Different stuff 1 200 100 100 DC Different stuff 1 300 150 DC Different stuff 1 400 200 DN2 Similar stuff 1 100 50 50 DN2 Similar stuff 1 200 100 100 DN2 Similar stuff 1 300 150 DN2 Similar stuff 1 400 200 </pre> <p>It is not what you would expect, because I do not understand why you have different values in <code>DLLRS_AC</code> column that are in the <code>CK_PRICE</code> table? I mean, for example, why do you have <code>400</code> in last line of your output, not <code>200</code>? Why is this value doubled (as others are in <code>DLLRS_AC</code> column)?</p> <p>If you are using Oracle 10g, you can achieve the same result using <code>DECODE</code> and <code>GROUP BY</code>, take a look:</p> <pre><code>SELECT cd, dsc, part_cd, qty, SUM(DECODE(cu_type, 'A', dllrs, NULL)) AS dllrs_a, SUM(DECODE(cu_type, 'AC', dllrs, NULL)) AS dllrs_ac FROM ( SELECT cs.cd, cs.dsc, cp.part_cd, cp.qty, cp.dllrs, cp.cu_type FROM ck_startup cs JOIN ck_price cp ON (cs.prd_type_cd = cp.prd_type_cd) ) GROUP BY cd, dsc, part_cd, qty ORDER BY cd, qty; </code></pre> <p>Result is the same.</p> <p>If you want to read more about pivoting, I recommend article by Tim Hall: <a href="http://www.oracle-base.com/articles/11g/pivot-and-unpivot-operators-11gr1.php" rel="nofollow">Pivot and Unpivot at Oracle Base</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload