[英]Select values from the same column
I have a database related question for WordPress. 我有一个与WordPress有关的数据库相关问题。
My table is represented as follows: 我的表如下所示:
ID | ID | customID |
customID | column1 |
第1列| column2
专栏2
1 8 _item item number
2 8 _price item price
3 9 _item item number
4 9 _price item price
I want to retrieve the following rows using a MySQL SELECT
statement: 我想使用MySQL
SELECT
语句检索以下行:
CustomID | CustomID | _price |
_price | _item |
_item |
8 item price(from col2) item number(from col2)
9 item price(from col2) item number(from col2)
Is this possible? 这可能吗? The value
_price
and _item
should be shown as columns with values from column2. 值
_price
和_item
应该显示为具有column2值的列。 How to solve this? 如何解决呢?
Your tables are designed quite badly. 您的表设计很糟糕。 You should build an extra table which maps product and price.
您应该建立一个额外的表格来映射产品和价格。 However this is what you can do with your solution:
但是,这是您可以使用的解决方案:
Select t1.customID, t1.column2, t2.column2 from <tablename> t1,
<tablename> t2
where t1.customID = t2.customId
and t1.column1 like '_item'
and t2.column1 like '_price';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.