-4

i have this data in my table usersNB

sietID  week nb
AE001   W7  94
AE001   W45 88.1
AE001   W50 41.1
AE002   W7  62
AE002   W45 66.6
AE002   W50 33.2
AE003   W7  4
AE004   W7  12
AE004   W45 14.7
AE004   W50 8
AE005   W7  36.5
AE005   W45 39.7
AE005   W50 26.2

if it is possible make sql query to get this result like that

siteID   w7   w45    w50
AE001    94   88.1   41.1
AE004    12   14.7   8
juergen d
  • 201,996
  • 37
  • 293
  • 362
chall
  • 9
  • 7
  • Is that a puzzle? Please describe how to get to the result and what you tried to get there. – juergen d Mar 30 '15 at 10:32
  • I have a table in my database users that contains three columns weekID, siteid, numberUser and data such as I have put up, so I need a sql query that allows me to have the result like this siteID w7 w45 w50 AE001 94 88.1 41.1 AE004 12 14.7 8 ............ ........ – chall Mar 30 '15 at 10:36
  • in the field weekID the data are w7, w45, w50, so i want to see that in the column and for each site id and for what week they nymber – chall Mar 30 '15 at 10:38
  • I think the responses above mean: can we see your attempt at a SQL query? – halfer Mar 30 '15 at 11:58

1 Answers1

-1

Yes it is possible doing the following query

select id.sideID, w7.nb, w45.nb, w50.nb
from usersNB id
left join usersNB w7 on
w7.siteID = id.siteID
and w7.week = 'w7'
left join usersNB w45 on
w45.siteID = id.siteID
and w45.week = 'w45'
left join usersNB w50 on
w50.siteID = id.siteID
and w50.week = 'w50'
where id.siteID in ('AE001', 'AE004')
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56