troubleshooting Question

SQL for getting two values per result from one table

Avatar of MartinC
MartinC asked on
SQL
7 Comments1 Solution294 ViewsLast Modified:
Hi all ... scratching my head over this, but I suspect experts here may know it ...

If a table has fields:

PersonID (integer)
GMTDate (date)
TimePeriod (integer)
Channel (integer)
ReadIngValue  (real)


Lets say the data looks like this:

PersonID     GMTDate     TimePeriod    Channel   ReadingValue
1            15-05-2008      1            7         4.6
1            15-05-2008      1            8         2.6
1            15-05-2008      1            9         3.1
1            15-05-2008      2            7         2.9
1            15-05-2008      2            8         4.0
1            15-05-2008      2            9         4.1
1            16-05-2008      1            7         3.3
1            16-05-2008      1            8         3.7
1            16-05-2008      1            9         0.4
2            15-05-2008      1            7         2.2
 

... and I need to get results back into one line of an SQL query from where I identify a date range and PersonID, and want TWO ReadingValue results for twoChannel number = 7 and Channel Number = 9 ... so that the result looks like this:

PersonID     GMTDate     TimePeriod   Channel7ReadingValue    Channel9ReadingValue
1            15-05-2008      1               4.6                      3.1
1            15-05-2008      2               2.9                      4.1
1            16-05-2008      1               3.3                      0.4

How should my SQL look?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros