日期:2014-05-16  浏览次数:20774 次

请教一个mysql查询语句,在线等,万分感谢!
我有一张mysql表xx,表里有字段名为的 a,b,c,d,e的字段,存放的是网址,用户提交数据(网址:v,w,x,y,z),想查询表xx里a,b,c,d,e任一字段是否包含提交的任一数据,或a 或b 或c 或d 或e,返回包含有提交数据之一的记录数量,请问这样的查询语句应该怎么写啊?希望有朋友能帮我一下,谢谢!

------解决方案--------------------
SQL code
mysql> select * from tend;
+----+----------------------+----------------------+----------------------+----------------------+----------------------+
| id | u1                   | u2                   | u3                   | u4                   | u5                   |
+----+----------------------+----------------------+----------------------+----------------------+----------------------+
|  1 | http://www.aaaa.com/ | http://www.bbbb.com/ | http://www.cccc.com/ | http://www.dddd.com/ | http://www.eeee.com/ |
|  2 | http://www.ffff.com/ | http://www.gggg.com/ | http://www.hhhh.com/ | http://www.iiii.com/ |                      |
|  3 | http://www.aa11.com/ | http://www.aa22.com/ | http://www.aa33.com/ | http://www.aa44.com/ | NULL                 |
|  4 | http://www.xx11.com/ | http://www.xx22.com/ | http://www.xx33.com/ | NULL                 | NULL                 |
|  5 | http://www.yy11.com/ | http://www.yy22.com/ | NULL                 | NULL                 | NULL                 |
|  6 | http://www.zz11.com/ | http://www.zz22.com/ | http://www.zz33.com/ | NULL                 | NULL                 |
+----+----------------------+----------------------+----------------------+----------------------+----------------------+
6 rows in set (0.00 sec)

mysql> select * from tend
    -> where find_in_set(u1,'http://www.gggg.com/,http://www.zz33.com/')
    -> or find_in_set(u2,'http://www.gggg.com/,http://www.zz33.com/')
    -> or find_in_set(u3,'http://www.gggg.com/,http://www.zz33.com/')
    -> or find_in_set(u4,'http://www.gggg.com/,http://www.zz33.com/')
    -> or find_in_set(u5,'http://www.gggg.com/,http://www.zz33.com/');
+----+----------------------+----------------------+----------------------+----------------------+------+
| id | u1                   | u2                   | u3                   | u4                   | u5   |
+----+----------------------+----------------------+----------------------+----------------------+------+
|  2 | http://www.ffff.com/ | http://www.gggg.com/ | http://www.hhhh.com/ | http://www.iiii.com/ |      |
|  6 | http://www.zz11.com/ | http://www.zz22.com/ | http://www.zz33.com/ | NULL                 | NULL |
+----+----------------------+----------------------+----------------------+----------------------+------+
2 rows in set (0.00 sec)

mysql>