select id,(select from student where id=t.id)+isnull((select from student where id=t.id+1),0) from student t
I want update the student table. thanks.
declare @Student table (Id int,Mark int) insert into @Student select 1,89 union all select 2,36SELECT a.id , a.Mark + ISNULL(b.Mark, 0) AS Mark FROM @Student a LEFT JOIN @Student b ON a.id = b.id - 1/* id Mark ----------- ----------- 1 125 2 36 */
UPDATE Student SET Mark= ( SELECT Mark FROM Student AS B WHERE B.ID=2 AND A.ID=1 ) this is my current sql clause, any bug or better sql clause.
update student set =a. from student inner join (select id, (select from student where id=t.id)+isnull((select from student where id=t.id+1),0) as from student t)a on student.id=a.id
DECLARE @Student TABLE (Id INT,Mark INT) INSERT INTO @Student SELECT 1,89 UNION ALL SELECT 2,36SELECT * FROM @Student UPDATE @Student SET Mark= ( SELECT Mark FROM @Student AS B WHERE B.ID=2 AND @Student.ID=1 ) Msg 137, Level 15, State 2, Line 14 Must declare the scalar variable "@Student".
update student set = + (select top 1 isnull(,0) from student t where t.id > student.id order by t.id)
update student set = (select sum() from id in (1,2)) where id = 1select * from student 1 125 2 36
没有定义A表,正确的语法参考如下: CREATE TABLE Student ( id INT, MARK INT ) INSERT INTO Student SELECT 1, 89 UNION ALL SELECT 2, 36 UNION ALL SELECT 3, 2UPDATE A SET MARK = MARK + ISNULL ( (SELECT MARK FROM Student AS B WHERE (B.ID=2 AND A.ID=1) OR (B.ID=3 AND A.ID=2)), 0 --注意这儿的原理 ) FROM Student A
select id,(select sum() from temp t1 where t1.id >= t2.id ) from temp t2
create table Student(Id int,Mark int) insert into Student values(1 ,89) insert into Student values(2 ,36) goselect t.id , = + isnull((select top 1 from student where id > t.id order by id),0) from student tdrop table student /* id ----------- ----------- 1 125 2 36(所影响的行数为 2 行) */
UPDATE Student SET Mark=Mark+ISNULL((SELECT Mark FROM Student WHERE ID=2),0) WHERE ID=1
declare @Student table (Id int,Mark int)
insert into @Student
select 1,89 union all
select 2,36SELECT a.id ,
a.Mark + ISNULL(b.Mark, 0) AS Mark
FROM @Student a
LEFT JOIN @Student b ON a.id = b.id - 1/*
id Mark
----------- -----------
1 125
2 36
*/
SET Mark=
(
SELECT Mark FROM Student AS B
WHERE B.ID=2 AND A.ID=1
)
this is my current sql clause, any bug or better sql clause.
update student set =a. from
student inner join
(select id,
(select from student where id=t.id)+isnull((select from student where id=t.id+1),0) as
from student t)a
on student.id=a.id
DECLARE @Student TABLE (Id INT,Mark INT)
INSERT INTO @Student
SELECT 1,89
UNION ALL
SELECT 2,36SELECT *
FROM @Student
UPDATE @Student
SET Mark=
(
SELECT Mark FROM @Student AS B
WHERE B.ID=2 AND @Student.ID=1
)
Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@Student".
update student
set = + (select top 1 isnull(,0)
from student t
where t.id > student.id
order by t.id)
update student
set = (select sum() from id in (1,2))
where id = 1select * from student 1 125
2 36
CREATE TABLE Student
(
id INT,
MARK INT
)
INSERT INTO Student
SELECT 1, 89 UNION ALL
SELECT 2, 36 UNION ALL
SELECT 3, 2UPDATE A
SET MARK = MARK + ISNULL
(
(SELECT MARK FROM Student AS B WHERE (B.ID=2 AND A.ID=1) OR (B.ID=3 AND A.ID=2)), 0 --注意这儿的原理
)
FROM Student A
select id,(select sum() from temp t1 where t1.id >= t2.id )
from temp t2
insert into Student values(1 ,89)
insert into Student values(2 ,36)
goselect t.id , = + isnull((select top 1 from student where id > t.id order by id),0) from student tdrop table student /*
id
----------- -----------
1 125
2 36(所影响的行数为 2 行)
*/
SET Mark=Mark+ISNULL((SELECT Mark FROM Student WHERE ID=2),0)
WHERE ID=1