gpt4 book ai didi

mysql - 查询以找出每个员工的出生日期

转载 作者:行者123 更新时间:2023-11-30 23:54:05 26 4
gpt4 key购买 nike

我试过这段代码。但它不起作用。(我使用的是 NetBeans 内部数据库)

代码是-

SELECT DATEPART(yyyy,DOB) AS BirthYear,
DATEPART(mm,DOB) AS BirthMonth,
DATEPART(dd,DOB) AS BirthDay
FROM Employees
WHERE EmpId=1

Error-

[Exception, Error code 30,000, SQLState 42X04] Column 'YYYY' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'DD' is not a column in the target table.

最佳答案

如果您使用的是 mysql,则假设 DOB 是有效的日期列,您应该使用 year()、month() 和 day() 而不是 datepart ..

SELECT year(DOB) AS BirthYear,
month(DOB) AS BirthMonth,
day(DOB) AS BirthDay
FROM Employees
WHERE EmpId=1

(如果是 sqlserver 的日期部分)

对于每个员工,您可以

SELECT EmpId,
year(DOB) AS BirthYear,
month(DOB) AS BirthMonth,
day(DOB) AS BirthDay
FROM Employees

关于mysql - 查询以找出每个员工的出生日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43298808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com