繁体   English   中英

选择空记录取决于左联接其他表

[英]Selecting empty records depending on left join other table

我在下面有一条选择语句。 tblplayer包含Game ='FPS'的709条记录。 tblPlayerPoints包含1条记录,其值分别为(2,'FPS',812,0)。 sql应该返回709条记录,我可以使用这些记录插入值(1,'FPS',playerid,0)。 但是,在运行下面的SELECT时,它仅返回708条记录。 因此,它排除了所有已经存在的记录。

它应该忽略该记录,因为第一个值(2)与新的第一个值(1)不同。 我尝试添加AND tblPlayerPoints.Gamenumber <2,但是得到0条记录,而不是709条。

删除tblPlayerPoints.Points IS NULL后,我确实获得了709条记录。 但是我无法删除该行,因为如果已经准备就绪的值(1,FPS,playerid,0)的行已经存在,则不应再添加该行。

SELECT 1 , 'FPS', tblPlayer.PlayerId, 0
FROM tblPlayer
LEFT JOIN tblPlayerPoints ON tblPlayer.Id = tblPlayerPoints.PlayerId
WHERE tblPlayer.Game = 'FPS'
AND tblPlayer.Subscription = '1'
AND tblPlayerPoints.Points IS NULL 

完整插入示例:

INSERT INTO tblpronoploegritpunten ("1","FPS",PlayerId,"0") 
SELECT 1 , 'FPS', tblPlayer.PlayerId, 0
FROM tblPlayer
LEFT JOIN tblPlayerPoints ON tblPlayer.Id = tblPlayerPoints.PlayerId
WHERE tblPlayer.Game = 'FPS'
AND tblPlayer.Subscription = '1'
AND tblPlayerPoints.Points IS NULL 

此完整插入应将709条记录添加到tblPlayerPoints中。如果我将完整插入示例(订阅除外)中的“ 1”更改为“ 2”,则仅应添加708条记录,因为已经有一条记录从值2开始。

根据我对您的问题的了解,

and tblPlayerPoints.Gamenumber is null

你可能想和

and IFNULL(tblPlayerPoints.Gamenumber,0) <> 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM