sql

table    StudentId         Mark   
1           89     
2           36    
write a sql clause , merge Id=2 to Id=1.  
 =>
1          125
2          36 

解决方案 »

  1.   

    select id,(select  from student where id=t.id)+isnull((select  from student where id=t.id+1),0) from student t
      

  2.   

    I want update the student table. thanks.
      

  3.   


    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
    */
      

  4.   

    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.
      

  5.   


    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
      

  6.   


    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".
      

  7.   


    update student
    set  =  + (select top 1 isnull(,0)
                       from student t
                       where t.id > student.id
                       order by t.id)
      

  8.   


    update student 
    set  = (select sum() from id in (1,2))
    where id = 1select * from student 1   125
    2   36
      

  9.   

    没有定义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
      

  10.   


    select id,(select sum() from temp t1 where t1.id >= t2.id  )
    from temp t2
      

  11.   

    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 行)
    */
      

  12.   

    UPDATE Student   
    SET Mark=Mark+ISNULL((SELECT Mark FROM Student WHERE ID=2),0)
    WHERE ID=1