Mysql在查询之间多次

时间:2013-09-08 17:37:29

标签: php mysql

我需要显示年龄结果差异 年龄在5到10岁之间,年龄在50到55之间

我使用了这个查询

$sql = "select name,age from tbl where (age BETWEEN 5 AND 10) OR (age BETWEEN 50 AND 55)";
$res = mysql_query($sql)

感谢。

1 个答案:

答案 0 :(得分:0)

select name,age, case when age BETWEEN 5 AND 10
                      then '5-10'
                      else '50-55'
                end as age_between
from tbl 
where ( age BETWEEN 5 AND 10)  
or (age BETWEEN 50 AND 55)
顺便说一句,存储生日更好。然后你不必设定年龄。