mysql能用value做字段吗_mySQL使用表的值作为字段来获取查询(mySQL using value of a table as a field to get query)...

Don't be confused, first of all, Table A should have: id+product-name. The product-id of table B have to refer to id of table A. To make so, both fields must keep the same format. For instance, integer. So your table B would look like follows.

product_id + product_type + product_num

1 + red + 10

1 + blue + 20

2 + red + 5

2 + blue + 15

To get what you want, you can try:

select unique product-name, B.product-num as red-num, C.product-num as blue-num from B, B as C, A where A.id=B.product-id and A.id=C.product-id and B.product-type="red" and C.product-type="blue";

I haven't tested it, since I haven't a mysql server running at the momment. Hope it works. Remove the unique if it doesn't work, you may get something similar to what you need.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值