我在vb.net中实现此查询时遇到问题。 我得到的错误消息是第一行中的“as”。 这是一个本地的sql compact数据库3.5
cmd.CommandText = "UPDATE player as a " &
"SET starter = 'TRUE' " &
"WHERE NOT EXISTS (SELECT '1' " &
"FROM player AS b " &
"WHERE(b.school = a.school) " &
"AND b.weight = a.weight " &
"AND b.skill > a.skill)"
cmd.ExecuteNonQuery()
错误讯息 - http://i40.tinypic.com/34gms5z.png
cmd.CommandText = "UPDATE a " &
"SET starter = 'TRUE' " &
"FROM player a " &
"LEFT JOIN player b " &
"ON a.school = b.school " &
"AND a.weight = b.weight " &
"AND b.skill > a.skill " &
"WHERE b.school is NULL"
cmd.ExecuteNonQuery()
答案 0 :(得分:1)
这有用吗?
UPDATE player
SET starter = 'TRUE'
WHERE NOT EXISTS
(
SELECT * FROM player b
WHERE b.school = player.school
AND b.weight = player.weight
AND b.skill > player.skill
)
已编辑添加:
如果您创建索引,这可能会运行得更快:
CREATE INDEX player_school_weight ON player (school, weight, skill)
答案 1 :(得分:0)
我相信你想要这个:
UPDATE pl
SET
starter = 'True'
FROM
[Player] pl
LEFT JOIN
[Player] pl2 ON (pl.[School] = pl2.[School])
AND
(pl.[Weight] = pl2.[Weight])
AND
(pl2.[Skill] > pl.[Skill])
WHERE pl2.[School] IS NULL