SQL 查询以查找 2000 年之前出生的人
SQL Query to find who are born until the year 2000
Two relationships are given:
Employee (AngID, Name, Surname, Date of Birth, Gender, Education, Position, Monthly Salary, DepID)
Department (DepID, DepName, City)
Print the SQL statement or statements that solve the following problem:
To display the number of employees according to the year of birth, who are born until the year 2000. The following will be displayed: Year, Number. The tuples will be ordered in descending order of the year of birth.
我试过这个:
SELECT Year, Number
FROM Employee
WHERE Date of Birth <2000 AS Num
ORDER BY Date of Birth DESC
我假设这是您要查询的内容:
SELECT YEAR(DateofBirth) as Year, Count(1) AS NumberOfEmployees
FROM Employee
WHERE DateofBirth < '2000-01-01'
GROUP BY YEAR(DateofBirth)
ORDER BY YEAR(DateofBirth) DESC
此查询将过滤所有 2000 年之前出生的员工。它将按年份对记录进行分组并显示计数。
sqlfiddle 例子
To display the number of employees
COUNT(*)
FROM Employee emp
according to the year of birth
GROUP BY DATEPART(YEAR, [Date of Birth])
who are born until the year 2000.
WHERE [Date of Birth] < '2001-01-01'
The following will be displayed: Year, Number.
DATEPART(YEAR, [Date of Birth]) AS [Year],
COUNT(*) AS [Number]
The tuples will be ordered in descending order of the year of birth.
ORDER BY [Year] DESC
SQL:
SELECT
DATEPART(YEAR, [Date of Birth]) AS [Year]
, COUNT(*) AS [Number]
FROM Employee emp
WHERE [Date of Birth] < '2001-01-01'
GROUP BY DATEPART(YEAR, [Date of Birth])
ORDER BY [Year] DESC
Two relationships are given: Employee (AngID, Name, Surname, Date of Birth, Gender, Education, Position, Monthly Salary, DepID) Department (DepID, DepName, City)
Print the SQL statement or statements that solve the following problem: To display the number of employees according to the year of birth, who are born until the year 2000. The following will be displayed: Year, Number. The tuples will be ordered in descending order of the year of birth.
我试过这个:
SELECT Year, Number
FROM Employee
WHERE Date of Birth <2000 AS Num
ORDER BY Date of Birth DESC
我假设这是您要查询的内容:
SELECT YEAR(DateofBirth) as Year, Count(1) AS NumberOfEmployees
FROM Employee
WHERE DateofBirth < '2000-01-01'
GROUP BY YEAR(DateofBirth)
ORDER BY YEAR(DateofBirth) DESC
此查询将过滤所有 2000 年之前出生的员工。它将按年份对记录进行分组并显示计数。
sqlfiddle 例子
To display the number of employees
COUNT(*)
FROM Employee emp
according to the year of birth
GROUP BY DATEPART(YEAR, [Date of Birth])
who are born until the year 2000.
WHERE [Date of Birth] < '2001-01-01'
The following will be displayed: Year, Number.
DATEPART(YEAR, [Date of Birth]) AS [Year],
COUNT(*) AS [Number]
The tuples will be ordered in descending order of the year of birth.
ORDER BY [Year] DESC
SQL:
SELECT
DATEPART(YEAR, [Date of Birth]) AS [Year]
, COUNT(*) AS [Number]
FROM Employee emp
WHERE [Date of Birth] < '2001-01-01'
GROUP BY DATEPART(YEAR, [Date of Birth])
ORDER BY [Year] DESC