mysql中一个字段多行展示_MySQL从表中选择一个字段,条件在多行中

bd96500e110b49cbb3cd949968f18be7.png

Tried to find the answer, but still couldn't.. The table is as follows:

id, keyword, value

1 display 15.6

1 harddrive 320

1 ram 3

So what i need is something like this.. Select an id from this table where (keyword="display" and value="15.6") AND (keyword="harddrive" and value="320")

There's also a possibility that there will be 3 or 4 such keyword conditions which should result into returning one id (one row)

It seems there's something to deal with UNION but i didn't use it before so i can't figure it out

Thanks in advance

解决方案

This is a relational division problem. Something like the following should do it.

SELECT id

FROM your_table

WHERE

(keyword="display" and value="15.6") OR (keyword="harddrive" and value="320")

GROUP BY id

HAVING COUNT(*) = 2

I'm assuming that your table has appropriate constraints such that it is impossible for there to be a completely duplicated row. (e.g. there is a PK on id, keyword)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值