sql server - sql - select from many to retrieve data in horizontal, data of one table as columns -


  • i have table t1 (idt1, name)
  • i have table t2 (idt2, optiondescription)
  • finally have table t3 (idt3, t1id, t2id, selected)

suppose have in t1:

idt1    name 1       john 2       mary 3       bill 

and in t2

idt2    optiondescription 1       "available on monday" 2       "available on tuesdey" 3       "available nights" 

and in t3

idt3    t1id    t2id    selected 1       1       1       true 2       1       2       true 3       1       3       false 4       2       1       false 5       2       2       false 6       2       3       true 

is possible write query retrieve data of t1 , t2/t3 in "horizontal" way (i mean description of t2 column result) like:

idt1    name    "available on monday"   "available on tuesdey"  "available nights" 1       john    true                    true                    false 2       mary    false                   false                   true 

use pivot

select *  ( select t1.idt1,t1.name,t2.optiondescription,selected t1   inner join t3 on t1.idt1=t3.idt2  inner join t2 on t2.idt2=t3.idt3 )x pivot ( max(selected) x.optiondescription in ([available on monday],[available on tuesdey],[available nights]) ) pvt 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -