0

我需要显示年龄结果差异,例如 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)

谢谢。

4

1 回答 1

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)

顺便说一句,最好存储生日。然后你不必设置年龄。

于 2013-09-08T17:38:55.873 回答