Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Joining corresponding values in a table
    primarykey
    data
    text
    <p>So I have a table (call it tbl1) that looks like (but with much more rows) :</p> <pre><code> CUSIP_ID1 CUSIP_ID2 cor dt_pnts 921910709 06738G407 0.99613 252 739371102 06738G407 0.380706 213 808524654 06738G407 0.580574 221 78467V202 06738G407 0.366938 224 808524854 06738G407 0.0127264 232 78567V103 06738G407 0.0799898 198 </code></pre> <p>etc.</p> <p>My code is (the second table tbl2 just has an ID# that i use to match values)</p> <pre><code>insert into tbl3 (Ticker, cusip_id, maxcor) select b.ID, a.CUSIP_ID1 No_indx_cusip, MAX(abs(a.cor)) maxcor from tbl1 a, tbl2 b where a.CUSIP_ID1 = b.CUSIP_ID group by a.CUSIP_ID1, b.Ticker order by maxcor desc select * from tbl3 </code></pre> <p>which returns</p> <pre><code> Ticker No_Indx_cusip maxcor dt_pnts EDV 921910709 0.99613 NULL SCHR 808524854 0.989976 NULL VGIT 92206C706 0.988307 NULL ELD 97717X867 0.985073 NULL PDP 73935X153 0.979131 NULL TTFS 00768Y818 0.974691 NULL SCHO 808524862 0.974254 NULL RLY 78467V103 0.951472 NULL PXLG 739371102 0.937278 NULL VCIT 92206C870 0.934389 NULL INKM 78467V202 0.921616 NULL WDTI 97717W125 0.890677 NULL CEW 97717W133 0.847838 NULL </code></pre> <p>I would like to select corresponding dt_pnts from tbl1 that match up with the max(abs(a.cor)) value into tbl3 from tbl1 (not working for me for some reason) - i.e. the value of 0.99613 would correspond to dt_pnts value of 252. Thanks!</p> <p>the result would look like </p> <pre><code>Ticker No_Indx_cusip maxcor dt_pnts EDV 921910709 0.99613 252 SCHR 808524854 0.989976 124 VGIT 92206C706 0.988307 252 ELD 97717X867 0.985073 79 PDP 73935X153 0.979131 89 TTFS 00768Y818 0.974691 252 SCHO 808524862 0.974254 198 RLY 78467V103 0.951472 38 PXLG 739371102 0.937278 138 VCIT 92206C870 0.934389 212 INKM 78467V202 0.921616 90 WDTI 97717W125 0.890677 16 CEW 97717W133 0.847838 153 </code></pre>
    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. 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