dmr*_*dmr 1 sql sql-server select
此查询有效:
SELECT u.UserId, u.GroupId, u.username,
gp.PreferenceId, gp.Properties, gp.Override
FROM dbo.UserTable u
Inner JOIN
dbo.GroupPreferences gp ON gp.GroupID = u.GroupId
WHERE (u.UserName = 'myUserId')
Run Code Online (Sandbox Code Playgroud)
但是另一个查询中的相同查询却没有.我收到错误"无效的列名'GroupId'"和"无效的列名'UserId'".我想有一个额外的(或)某个地方; 请帮帮我找到它!
外部查询:
SELECT coalesce(t1.PreferenceId,up.preferenceId)
as preferenceId, CASE t1.override WHEN 1 THEN COALESCE
(up.properties, t1.properties)
When 0 then t1.properties
ELSE up.properties END AS Properties
FROM
(SELECT u.UserId, u.GroupId, u.username,
gp.PreferenceId, gp.Properties, gp.Override
FROM dbo.UserTable u
Inner JOIN
dbo.GroupPreferences gp ON gp.GroupID = u.GroupId
WHERE (u.UserName = 'myUserId')) t1
full OUTER JOIN
(select preferenceId, properties from UserPreferences u
inner join userTable t on u.userId = t.userId and u.GroupId =
t.GroupId where userName = 'myUserId') up
ON t1.GroupId = up.GroupID AND t1.UserId = up.UserId
AND t1.PreferenceId = up.PreferenceId
Run Code Online (Sandbox Code Playgroud)
您正在引用列GroupId和UserId内联视图别名up,但它的选择列表中不包括这些列.
更改第14行以包含这些列:
(select t.GroupId, t.userId, preferenceId, properties from UserPreferences u
Run Code Online (Sandbox Code Playgroud)