简体   繁体   English

我怎样才能加入同一张桌子给我带来一个结果?

[英]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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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