一个按字段顺序对比内容的问题
遇到个问题,向大家请教,表的结构如下
id name
1 lily
1 tom
1 john
2 lily
2 tom
2 john
... ...
... ...
n lily
n tom
n john
现在要判断所有id的对应的name必须都含有lily tom john,并且顺序必须为lily tom john
我自己的办法是 select name from students where id = 1
把id为1的名字都取出来,依次和lily tom john 做比较。
这样就得写n条类似select name from students where id = 1 的sql语句(因为student中有n个不同的id)
想跟大家请教下怎么样可以用一条sql解决这个问题。