Jump to content
  • 0

Unpivot, Select Id & Group By





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

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.
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
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

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.

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.

  • Create New...