Jump to content
  • 0
Sign in to follow this  
Elena

Unpivot, Select Id & Group By

Question

Hello, 

 

I am going to try to make sense and comprehensible in explaining.

 

Essentially, I am trying to pick the maximum value (per record ID) out of the entire data table with multiple columns, and put this value in each corresponding row for each ID.

 

For some reason, "SELECT ID, and GROUP BY ID"  doesn't seem to be working in Caspio. 

 

My information is below: The problem with this code is that, it is finding the max alright, but it is putting the same value into each record.

 

How can I correct this so that each record ID will have the right maximum value? 

For example:  ID 123 = $97,900,   ID 456 = $83,820   ID 789 = $59,730

 

 

Table name:  market_data

 
ID
123
456
789
 
PayscaleAverage
$89,000
$76,200
$54,300
 
ERI_Median
$97,900
$83,820
$55,321
 
Miliman_Avg 
$91,670.00
$78,486.00
$59,730.0
 
 
Here is the SQL Query: 
I am using UNPIVOT function.
 
SELECT  MAX(highestdata) AS maxnumber
FROM market_data
UNPIVOT (highestdata FOR Val IN (PayscaleAverage, ERI_Median, Miliman_Avg )) AS Number
WHERE ID = [@field:ID_Lookup]
I appreciate any help. Thank you in advance.
 
 
P.S. 
 
Please, if you could, please do not recommend conditionals, such as,  "WHEN Col1 < Col2 then..."
because this table has over 200 columns.
 
Edited by Elena

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hello there aa82, 

 

I am happy to report back that your recommendation worked. My filter is now operating fully as intended with a simple addition or "target".  

 

Thank you so much.

 

E

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...