mysql distinct 条件_多行条件下的mysql distinct列(mysql distinct column on multiple row conditions)...

I have a mysql database (item_preset) with the following table:

+-----+-----------+---------+-------+

| id | preset_id | item_id | value |

+-----+-----------+---------+-------+

| 1 | 1 | 1 | 2 |

| 2 | 1 | 2 | 1 |

| 3 | 1 | 4 | 60 |

| 4 | 1 | 3 | 16 |

| 5 | 1 | 3 | 17 |

| 6 | 1 | 3 | 18 |

| 7 | 1 | 3 | 25 |

| 8 | 1 | 3 | 26 |

| 9 | 1 | 3 | 27 |

| 10 | 2 | 1 | 3 |

| 11 | 2 | 2 | 0 |

| 12 | 2 | 4 | 0 |

| 13 | 2 | 3 | 16 |

| 14 | 2 | 3 | 17 |

| 15 | 2 | 3 | 19 |

| 16 | 2 | 3 | 20 |

| 17 | 2 | 3 | 21 |

| 18 | 3 | 1 | 2 |

| 19 | 3 | 2 | 0 |

| 20 | 3 | 4 | 0 |

| 21 | 3 | 3 | 25 |

| 22 | 3 | 3 | 28 |

| 23 | 4 | 1 | 1 |

| 24 | 4 | 2 | 1 |

| 25 | 4 | 4 | 120 |

| 26 | 4 | 3 | 16 |

| 27 | 4 | 3 | 17 |

| 28 | 4 | 3 | 18 |

| 29 | 4 | 3 | 22 |

| 30 | 4 | 3 | 23 |

| 31 | 4 | 3 | 24 |

| 32 | 6 | 1 | 3 |

| 33 | 6 | 2 | 1 |

| 34 | 6 | 4 | 90 |

| 35 | 6 | 3 | 18 |

| 36 | 6 | 3 | 22 |

| 37 | 6 | 3 | 23 |

| 38 | 6 | 3 | 24 |

| 39 | 6 | 3 | 29 |

| 40 | 6 | 3 | 30 |

+-----+-----------+---------+-------+

What I would like to do is get the distinct preset_id based on conditions from multiple rows. eg to get preset_id 1 i need all the conditions to be true (item_id = 1 and value_id = 2), (item_id = 2 and value = 1), etc...

I have tried usintg the following: select distinct preset_id from item_preset where (item_id = 1 and value = 2) and (item_id = 2 and value = 1) and (item_id = 4 and value = 60);

but get an Empty Set. If I try with Or's instead of and I get all preset_ids that match any of the conditions.

Any Ideas?

Thanks

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值