我正在努力计算最老的人的年龄,并且只显示来自一个群体的那个人。
下面这段代码给了我合适的人但是年龄不正确(Margret,69)
app.post('/profile', upload.single('avatar'), function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
下面这段代码给了我所有的人和正确的年龄(Margret,58)
SELECT FirstName as Name,
max((strftime('%Y', 'now') - strftime('%Y', BirthDate))
- (strftime('%m-%d', 'now') < strftime('%m-%d', BirthDate) )) as Age
FROM Employee;
有人可以帮忙解释一下吗?
答案 0 :(得分:0)
这可能取决于你的BirthDate
如何定义,但如果它是sqlite3标准yyyy-mm-dd尝试:
SELECT FirstName as Name, CAST( (julianday('now') - julianday(BirthDate)) / 365 AS INTEGER) as age
FROM Employee;
和
SELECT FirstName as Name, max(CAST( (julianday('now') - julianday(BirthDate)) / 365 AS INTEGER)) as age
FROM Employee;