In the SQL language. Find 1 2 3 ... 100 of the sum. Thank you

Updated on educate 2024-04-28
3 answers
  1. Anonymous users2024-02-08

    To add a note: the following examples have passed my test, so you can use them with confidence.

    Oracle.

    set serveroutput on;

    declare

    sums int;

    i int;

    beginsums:=0;

    i:=1;while i<=100

    loopsums:=sums+i;

    i:=i+1;

    end loop;

    dbms_'Integers within 100 and :'||sums);end;

    sqlserver.

    declare @i int;

    declare @sums int;

    set @i=1;

    set @sums=0;

    while (@i<=100)

    beginset @sums=@sums+@iset @i=@i+1

    endselect @sums

    Above, I hope it will help you.

  2. Anonymous users2024-02-07

    Create a stored procedure.

    create proc addtotal

    asdeclare @num int,@result intbeginset @num=1

    set @result=0

    while 1=1

    beginif @num>100

    breakelse

    beginset @result=@result+@numset @num=@num+1

    endend

    print 'The result of the calculation is:'+convert(varchar(10),@result)

    endexec addtotal

  3. Anonymous users2024-02-06

    s=a1+(a1+a2)+(a1+a2+a3)s=b1+b2+b3

    a2=a1+2

    a3=a2+2

    --Get the general formula an=a(n-1)+2b1=a1

    b2=2*a1+2

    b3=3*a1+6

    Then we can get that the general term of bn is bn=n(a1+n-1), since a1=1, the value of bn is equal to the square of n, bn=n2, so.

    s=1^2+2^2+3^2+..The formula for the equation n 2 is (I have already returned it to the teacher after referring to the source) n(n+1)(2n+1) 6

    So s=n(n+1)(2n+1) 6

    So as long as the value of n is determined, it is only an expression to express it in sql, assuming n=3:

    select

Related questions
4 answers2024-04-28

Gives a function that determines whether a number is prime or not. >>>More

4 answers2024-04-28

select * from log a,(select ,max(date) from logwhere id='10000' >>>More

5 answers2024-04-28

bool f=0;

for(int i=1000;i>=1;i--) Start with the largest number of 1000 and try to the smaller number. >>>More

7 answers2024-04-28

Select Courses. Course name, course. Teacher's name from student, course, student selection. >>>More

3 answers2024-04-28

The base and high area of the simple input triangle are presented as follows: >>>More