作者grence (多想两分钟 = =")
看板Database
标题Re: [MySQL] 同Table中的交集运算
时间Fri May 22 04:37:27 2009
※ 引述《JYHuang (夏天到了,冷不起来了说)》之铭言:
: 有Table Product,Feature,Product_Feature
: Product是放产品资料的资料
: Feature的架构是一个清单式的列表
: id Feature
: 1 DVI
: 2 HDMI
: 3 DisplayPort
: 4 ......
: Product_Feature是对照表 (那些Product有那些Feature)
: Pid Fid
: 1 1
: 1 2
: 2 1
: 3 1
: 我想挑出同时有DVI 跟HDMI的Pid (只有1符合)
: 用where Fid In(1,2)的话 1,2,3都会被包含在内
: where (Fid=1 AND Fid=2) 也不被接受
: 请问有什麽方法可以做交集式的筛选呢?
1.把 fid串起来再比对,MySql有group_concat()
2.配合AP串 SQL做起来满直觉的……
pid in(select pid...where fid=1) and
pid in(select pid...where fid=2) and ..
就是感觉会很慢XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.229.202.143
1F:推 bobju:不会慢,我有时查询需要同时下数十个这类的条件式,还好.XD~ 05/22 09:16
2F:推 bobju:当然前提是index有先设好.. 05/22 09:26