給出了兩個關系: Employee(AngID,Name,Surname,Date of Birth,Gender,Education,Position,Monthly Salary,DepID) Department(DepID,DepName,City)
列印解決以下問題的一個或多個 SQL 陳述句: 顯示從出生年份到 2000 年出生的員工人數。將顯示以下內容:Year, Number。元組將按出生年份的降序排列。
我試過這個:
SELECT Year, Number
FROM Employee
WHERE Date of Birth <2000 AS Num
ORDER BY Date of Birth DESC
uj5u.com熱心網友回復:
我假設這是您所追求的查詢:
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示例
uj5u.com熱心網友回復:
顯示員工人數
COUNT(*)
FROM Employee emp
根據出生年份
GROUP BY DATEPART(YEAR, [Date of Birth])
出生到 2000 年的人。
WHERE [Date of Birth] < '2001-01-01'
將顯示以下內容:年份、編號。
DATEPART(YEAR, [Date of Birth]) AS [Year],
COUNT(*) AS [Number]
元組將按出生年份的降序排列。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/414980.html
標籤:
