Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8023719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:38:33+00:00 2026-06-04T22:38:33+00:00

I have this table below How do I make the output like this I

  • 0

I have this table below

enter image description here

How do I make the output like this

enter image description here

I did the output above using this query:

SELECT DISTINCT 
    C.RefVal, 
    C.CalibrationEventID, 
    C1.Result As "Trial One", 
    C2.Result AS "Trial Two", 
    C3.Result AS "Trial Three", 
    C4.Result AS "Trial Four", 
    C5.Result AS "Trial Five" 
FROM CalibrationTrials AS C 
INNER JOIN 
    (SELECT DISTINCT RefVal, Result FROM CalibrationTrials WHERE CalibrationEventID = 'CAL000001' AND RefVal = '1.0010'AND TrialNo = 1) As C1 
ON C1.RefVal = C.RefVal
INNER JOIN 
    (SELECT DISTINCT RefVal, Result FROM CalibrationTrials WHERE CalibrationEventID = 'CAL000001' AND RefVal = '1.0010'AND TrialNo = 2) As C2 
ON C2.RefVal = C.RefVal
INNER JOIN 
    (SELECT DISTINCT RefVal, Result FROM CalibrationTrials WHERE CalibrationEventID = 'CAL000001' AND RefVal = '1.0010'AND TrialNo = 3) As C3 
ON C3.RefVal = C.RefVal
INNER JOIN 
    (SELECT DISTINCT RefVal, Result FROM CalibrationTrials WHERE CalibrationEventID = 'CAL000001' AND RefVal = '1.0010'AND TrialNo = 4) As C4 
ON C4.RefVal = C.RefVal
INNER JOIN 
    (SELECT DISTINCT RefVal, Result FROM CalibrationTrials WHERE CalibrationEventID = 'CAL000001' AND RefVal = '1.0010'AND TrialNo = 5) As C5 
ON C5.RefVal = C.RefVal

WHERE C.CalibrationEventID = 'CAL000001' AND C.RefVal = '1.0010'
ORDER BY C.RefVal, C.CalibrationEventID

Apparently with this query the output is only fixed to one RefVal which is ‘1.0010’

What would be the correct query to output image2 format for each RefVal of a CalibrationEventID?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:38:36+00:00Added an answer on June 4, 2026 at 10:38 pm

    Here’s how you can use a PIVOT clause for your query:

    SELECT
      RefVal,
      CalibrationEventID,
      [1] AS [Trial One],
      [2] AS [Trial Two],
      [3] AS [Trial Three],
      [4] AS [Trial Four],
      [5] AS [Trial Five],
      [6] AS [Trial Six]
    FROM CalibrationTrials
    PIVOT (
      MAX(Result) FOR TrialNo IN ([1], [2], [3], [4], [5], [6])
    ) AS p
    

    The above assumes that your table consists only of columns RefVal, CalibrationEventID,
    TrialNo, Result
    . If there are more columns in the table, you should first select these four separately, then apply PIVOT. Here:

    SELECT
      RefVal,
      CalibrationEventID,
      [1] AS [Trial One],
      [2] AS [Trial Two],
      [3] AS [Trial Three],
      [4] AS [Trial Four],
      [5] AS [Trial Five],
      [6] AS [Trial Six]
    FROM (
      SELECT
        RefVal,
        CalibrationEventID,
        TrialNo,
        Result
      FROM CalibrationTrials
    ) AS c
    PIVOT (
      MAX(Result) FOR TrialNo IN ([1], [2], [3], [4], [5], [6])
    ) AS p
    

    This is needed because a PIVOT query is essentially a special case GROUP BY query. All columns except Result take part in grouping implicitly. That’s why you should get rid of those that are not needed in this kind of grouping.

    And here’s an alternative approach, without PIVOT:

    SELECT
      RefVal,
      CalibrationEventID,
      MAX(CASE TrialNo WHEN 1 THEN Result END) AS [Trial One],
      MAX(CASE TrialNo WHEN 2 THEN Result END) AS [Trial Two],
      MAX(CASE TrialNo WHEN 3 THEN Result END) AS [Trial Three],
      MAX(CASE TrialNo WHEN 4 THEN Result END) AS [Trial Four],
      MAX(CASE TrialNo WHEN 5 THEN Result END) AS [Trial Five],
      MAX(CASE TrialNo WHEN 6 THEN Result END) AS [Trial Six]
    FROM CalibrationTrials
    GROUP BY
      RefVal,
      CalibrationEventID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table structure and would like to map it using Fluent Hibernate
I have a table like this below. And there is a div container with
I have data in data table like below. I am trying to make graph
We have a composite primary key for the site table defined below. Functionally, this
I have this table: fourn_category (id , sub) I am using this code to
I have this query that i should make it run on SQL Azure. WITH
I have an html table like below +-------+-------+-------+-------+-------+---------+---------+---------+---------+ | col1 | col2 | col3
I have this query below. There are 4 main tables involved: tblOrder, tblItems, tblOrder_archive,
I have this code UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''+
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.