Click here to Skip to main content
15,067,832 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


I Want the Data to be below format structure. attached link is for better look


| headercolumn1 | headercolumn2 |
---------------------------------------------------------------
| col1 | col2 | col3 | col1 | col2 |col3 |
--------------------------------------------------------------
row1 |
---------------------------------------- --------------------
row2 |

What I have tried:

Which Method is the best way to write that as a SQL Query.
I've tried with 'When-case ' method but i didn't get the exact data.

Help me with that and Thanks in Advance.
Posted
Updated 9-Oct-20 22:58pm

1 solution

You can't - SQL doesn't "know" about headers - all it has is rows and columns, and the columns can - but don't have to - have names. And all the rows in a SELECT will return exactly the same number of columns.

Your presentation software can use the names to provide headers, but again it doesn't have to.

You need to retrieve the information from SQL then create your headers in your presentation software, not try to force SQL to do it for you. Think about it: SQL has no idea what your presentation software is going to do with it: it may not show it to the user at all but process it internally!
   
Comments
Member 14960657 12-Oct-20 3:00am
   
What You've said is right, I want the data in that Format as i mentioned. Forget About Headers and Consider them as Columns which is the best way to do it .
Thank you.
Member 14960657 12-Oct-20 3:27am
   
Period linename LossReason |Machine| Loss
10/7/2020 OD Grinding electrical Maintance G-140 21
10/7/2020 OD Grinding electrical Maintance G-140 10
10/7/2020 OD Grinding Mechine Maintance G-140 7200

the above is the Actual Data I want the Data in the Below Format

Electrical Maintance || Machine Maintance
--------------------------------------------------------------------------------------
linename machine Loss MTTR MTBF Loss MTTR MTBF
OD Grinding G-140 31 15 5024 7200 7200 2880
OD Grinding G-140 0 0 10080 0 0 10080
OriginalGriff 12-Oct-20 4:57am
   
And half the information you want isn't in the data you show!
Member 14960657 12-Oct-20 6:09am
   
Loss,MTTR and MTBF i'll get through calculation


OriginalGriff 12-Oct-20 6:53am
   
From what? Don't you think it might be important to know what data is needed and from where before you start designing random queries?

You can't calculate values without having access to the actual data to calculate from - and since we have no access to your data or idea how it is all related, there isn't a lot we can do.

What have you tried so far, and what does it give you?
Member 14960657 12-Oct-20 3:29am
   
Period linename LossReason |Machine| Loss
10/7/2020 OD Grinding electrical Maintance G-140 21
10/7/2020 OD Grinding electrical Maintance G-140 10
10/7/2020 OD Grinding Mechine Maintance G-140 7200

the above is the Actual Data I want the Data in the Below Format

Electrical Maintance || Machine Maintance
--------------------------------------------------------------------------------------
linename machine Loss MTTR MTBF Loss MTTR MTBF
OD Grinding G-140 31 15 5024 7200 7200 2880

Forget about MTTR and MTBF Calculations.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900