我正在嘗試使下面的查詢對另一個具有用戶名的表中的行進行計數。每個用戶名在統計表中有一行,但在用戶名爲pvp表中有多行。從pvptable加入的所有列顯示爲空,並且殺死了COUNT動態生成的死亡。這是SQL查詢。MySQL LEFT JOIN列爲空
SELECT
*,
pvptable.username AS USER,
COUNT(pvptable.killer) AS kills,
COUNT(pvptable.username) AS deaths,
ROUND(
COUNT(pvptable.killer)/COUNT(pvptable.username),
2
) AS kd
FROM
stats AS st
LEFT JOIN pvp AS pvptable
ON pvptable.killer = "Username"
AND pvptable.username = "Username"
WHERE st.username = "Username" ;
您的加盟條件有點可疑。 –
我會說, SELECT *,pvptable.username作爲用戶,COUNT(pvptable.killer)作爲殺害, COUNT(pvptable.username)作爲死亡, ROUND(COUNT(pvptable.killer)/ COUNT(pvptable.username) ,2)AS kd FROM stats as st LEFT JOIN pvp as pvptable ON pvptable.killer = st.username WHERE st.username =「Username」; – TranQ
將您的查詢更改爲此。編輯:「pvptable.killer = st.username」而不是「pvptable.killer =」用戶名「 – TranQ