Professional Documents
Culture Documents
SQL
SQL
=============================
declare @var int
set @var = 1
while @var <= 20
begin
print replicate('* ', @var)
set @var = @var + 1
end
o/p:
-----
*
* *
* * *
* * * *
* * * * *
print @Output;
#4 CASE WHEN
=========================
You can use case when statement inside aggregate functions
eg: select s.user_id,
sum(case when c.action='confirmed' then 1 else 0 end ) as confirmed_count,
count(*) as total_requests
from Signups s left join Confirmations c
on s.user_id = c.user_id
group by s.user_id
select id,
case when id%2<>0 and next_student is null then student
case when id%2<>0 then next_student
case when id%2=0 then prev_studnet
end as student
from
(
select id,
student,
lag(student) over (order by id asc) as prev_student,
lead(student) over (order by id asc) as next_student
from Seat
) a
order by id