简体   繁体   中英

How can I join the same table to bring me one result?

I want to create a query than bring me the following result:

Product | attibutname | attibutname      | Value |
   5547 | Lacoste     | Enable / Disable | 20
   5548 | Vans        | Enable / Disable | 10   

The table are look like this:

id | Product | Attributname     | value
 1 |    5547 | Brand            | Lacoste
 2 |    5547 | Woman /Mens      | 1
 3 |    5547 | Enable / Disable | 20
 4 |    5548 |  Brand           | Vans
 2 |    5548 | Woman /Mens      | 0
 3 |    5548 | Enable / Disable | 10

`

Something like the following is how you would join the table to itself(with assumptions from what you have provided). You would need to alias each copy so you know if you are talking about the brand or a different attribute row of the table.

Select b.Product, b.value [Attributename1], g.Attributename, g.value 
  from myItemTable b 
  join myItemTable g ON g.id = b.id 
 Where b.Attributename = 'Brand'
   and g.Attributename = 'Enable / Disable'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM