我試着寫一個MySQL的語句,將我帶回來這些結果INT比較:基於多少任務的每一天執行的每個員工沒有WHERE語句
## Name | Day 0 | Day 1 | Day 2 | Day 3 | Day 4 | Day 5 |
##Jeff | 0 | 3 | 1 | 2 | 1 | 1 |
##Larry | 1 | 1 | 4 | 4 | 1 | 0 |
。
我的數據庫表如下:
員工
id
(INT),number
(VARCHAR),name
(VARCHAR),dateStarted
(VARCHAR),
項目
id
(INT),number
(VARCHAR),dateEnded
(DATETIME)
現在,我用這樣的說法:
SELECT
a.name AS "Name",
count(abs(datediff(STR_TO_DATE(a.dateStarted, '%Y-%m-%d %H:%i:%s'), b.dateEnded))) AS "Day 0",
count(abs(datediff(STR_TO_DATE(a.dateStarted, '%Y-%m-%d %H:%i:%s'), b.dateEnded))) AS "Day 1",
count(abs(datediff(STR_TO_DATE(a.dateStarted, '%Y-%m-%d %H:%i:%s'), b.dateEnded))) AS "Day 2",
count(abs(datediff(STR_TO_DATE(a.dateStarted, '%Y-%m-%d %H:%i:%s'), b.dateEnded))) AS "Day 3",
count(abs(datediff(STR_TO_DATE(a.dateStarted, '%Y-%m-%d %H:%i:%s'), b.dateEnded))) AS "Day 4",
count(abs(datediff(STR_TO_DATE(a.dateStarted, '%Y-%m-%d %H:%i:%s'), b.dateEnded))) AS "Day 5"
FROM employee a, project b
WHERE b.number=a.number
AND "Day 0" = 0
AND "Day 1" = 1
AND "Day 2" = 2
AND "Day 3" = 3
AND "Day 4" = 4
AND "Day 5" >= 5
電流輸出
上述聲明的作品,但由於某種原因,沒有提供上述要求中提到的所需結果。關於如何修復/更改它的任何想法?
編輯
如果我冒了出來:
AND "Day 0" = 0
AND "Day 1" = 1
AND "Day 2" = 2
AND "Day 3" = 3
AND "Day 4" = 4
AND "Day 5" >= 5
然後打印出來:
## Name | Day 0 | Day 1 | Day 2 | Day 3 | Day 4 | Day 5 |
##Jeff | 9 | 9 | 9 | 9 | 9 | 9 |
'E之間沒有加入條件mployee'和'Project'? – hashbrown
'STR_TO_DATE(a.dateStarted,'%Y-%m-%d%H:%i:%s')是什麼意思?你的日期存儲爲字符串嗎? –
@hashbrown,如果兩個id是兩個單獨的東西(id爲person,id爲project),加入它們將毫無意義。如果他們提到同樣的事情(名字很差),那麼你可以把它們加入一張表中。 –