简体   繁体   English

MYSQL查询计数表行

[英]MYSQL query to count table row

I made a program with this code: 我用以下代码制作了一个程序:

select DATE_FORMAT(DATE_ADD(Birth_Date, INTERVAL '55 - 1' YEAR_MONTH), '01-%m-%Y')
AS Retire_Date
FROM employee

The question is how can I count amount of record Retire_Date in this month (example: February, 2016)? 问题是我如何计算本月的Retire_Date记录Retire_Date (例如:2016年2月)?

NOTE : retire_date column isn't exist on database data 注意: retire_date列在数据库数据上不存在

If I understood correctly, you want a query that returns how many people are retiring/retired in this the current month so: 如果我理解正确,那么您需要一个查询,该查询返回当月本月退休/退休的人数,因此:

SELECT count(*)
from employee
where year(DATE_FORMAT(DATE_ADD(Birth_Date, INTERVAL '55 - 1' YEAR_MONTH), '01-%m-%Y')) = year(curdate())
      and month(DATE_FORMAT(DATE_ADD(Birth_Date, INTERVAL '55 - 1' YEAR_MONTH), '01-%m-%Y')) = month(curdate())

Is this what you meant? 这是你的意思吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM