Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        5年前关闭。
                                                                                            
                
        
如何计算年龄等于18岁的人数?

<?php $emp_query=mysql_query("SELECT
  'employeeID',
  `LastName`,
  `birthday`,
  (YEAR(CURRENT_DATE)-YEAR(`birthday`))-(RIGHT(CURRENT_DATE,5)<RIGHT(`birthday`,5)
  ) AS `age`
FROM `employee`
ORDER BY `LastName`");
while($row=mysql_fetch_array($emp_query)){ $id=$row['employeeID']; ?>
                <td><?php echo $row['LastName']; ?></td>
                            <td><?php echo $row['birthday']; ?></td>
                            <td><?php  echo $row['age']?></td>

<?php } ?>

最佳答案

如果您对age计算感到满意,则可以将查询改写为:

SELECT COUNT(*)
FROM (SELECT (YEAR(CURRENT_DATE)-YEAR(`birthday`))-(RIGHT(CURRENT_DATE,5)<RIGHT(`birthday`,5)
             ) AS `age`
      FROM `employee`
     ) e
WHERE age = 18;

关于php - 如何计算年龄等于一定人数的人数? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27743142/

10-10 03:33