English 中文(简体)
多胎体最新说明
原标题:Update statement for multiple ids

我有3个表格,需要通过计算其他两个表格的数据来更新第3个表。

update table3 set column3=
(
select t2.column3+t1.column3
from table2 t2 with (nolock) join table1 t1
on table2.id=t1.id
where table2.id= 100
)
where id= 100;

但是,如果要向本国经营者提供此类服务,则会更新第3栏:

  update table3 set column3=
    (
    select t2.column3+t1.column3
    from table2 t2 with (nolock) join table1 t1
    on table2.id=t1.id
    where table2.id IN (100,101)
    )
    where id IN (100,101);

这失败了,一收到这一信息

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.

并且,我知道,这是因为分局正在返回1个以上,如何处理这种情况? 任何 h/ough都将是有益的。

How do i update for multiple ids? ie. the select query value returned by ID 100 should be updated against ID 100 in 3rd table & similarly for ID 101.

此外,我需要作一等(t2.coumn3)-(t1.coumn3 + t1.coumn2)

 update table3 set column3=
        (
        select  sum(t2.column3)- (t1.column3 + t1.column2)
        from table2 t2 with (nolock) join table1 t1
        on table2.id=t1.id
        where table2.id IN (100,101)
        )
        where id IN (100,101);
最佳回答

这是因为你试图将<条码>coln3设定为一种回报结果,而Kingk则认为只有一种价值(尺度)。 当你通过一个以上的回报价值(应当使用这一价值? ......它不会通过结果来推断出它)。 因此,如果你想要更新整个成果,那么你需要从你问询中设立一个分局,并加入。 你的问询更像这样看待。

UPDATE Table3
SET Column3 = subtable.value
FROM Table3 
    JOIN (
        select t2.column3+t1.column3 as value, t1.id
        from table2 t2 with (nolock) join table1 t1
        on table2.id=t1.id
        where table2.id IN (100,101)
    ) AS subtable
    ON subtable.id = Table3.id
WHERE table3.id IN (100, 101)

根据这一假设,表3.id与另一个脂重相匹配,你也确实不需要在表2.id内插入<代码>。

问题回答

页: 1 引证:

UPDATE t3
SET column3 = t2.column3+t1.column3
FROM table3 t3
INNER JOIN table2 t2 WITH(NOLOCK) 
ON t3.id = t2.id
INNER JOIN table1 t1
ON t3.id=t1.id
WHERE t3.id IN (100,101)




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签