我将此表命名为SubscriptionCharity,其内容如下:
SubscriptionId ChannelURI CharUserID
1 AX 12
2 ZA 7
3 AX 10
我想检查一个特定的CharUserId,如果表中的任何记录具有相同的通道uri并将其设置为null,那么在此表中“Subcriptionid = 1”应该设置为null
我有两个查询,一个在MS SQL Managment m中工作但不适用于LINQ: (它不会影响行)
UPDATE SubscriptionCharProg
Set ChannelURI = null
FROM SubscriptionCharProg as t1
INNER JOIN SubscriptionCharProg as t2
on t1.ChannelURI = t2.ChannelURI
and t1.DeviceId = t2.DeviceId
WHERE CharUserId! = 5
和另一个适用于LINQ但不适用于MS SQL Managment: (MS SQL管理错误:无效的对象名称“t1”)
context.ExecuteStoreCommand("UPDATE t1 Set t1.ChannelURI = 1 FROM SubscriptionCharProg as t1 INNER JOIN
SubscriptionCharProg as t2 on t1.ChannelURI = t2.ChannelURI WHERE t1.CharUserId! = "
+ charuserID + "", null);
另外,主要问题是,两个查询都使每个channelURi为空,无论它是否等于
有什么想法吗?
编辑:如果具有特定charuserID的记录存在两次或更多次,则保留并且不将其设置为空
答案 0 :(得分:0)
更改第一行:
UPDATE SubscriptionCharProg
到
UPDATE t1
答案 1 :(得分:0)
试试这个:
UPDATE t1
SET ChannelURI = null
FROM SubscriptionCharProg as t1
INNER JOIN SubscriptionCharProg as t2
on t1.ChannelURI = t2.ChannelURI
and t1.DeviceId = t2.DeviceId
and t1.CharUserID <> t2.CharUserID
WHERE t2.CharUserID = 5
答案 2 :(得分:0)
update quiz_subgroup as sg
inner join (select qq_qsg_id, count(qq_id) as cnt_ques from quiz_questions group by qq_qsg_id) as ques on(ques.qq_qsg_id = sg.qsg_id)
set sg.qsg_count_of_questions = ques.cnt_ques;