Monday, September 2, 2019

Count positive and Negative number

Count positive and Negative number

select Positive = count(case when num>0 then 1 else null end), negative =count(case when num<0 1="" else="" end="" from="" null="" p="" temp="" then="">
Ques : How to create backup table using query
Ans : Select * into table1 from table2.

Ques : How to get emp name whose salary is greater than average salary in the department?

;with as temp1(id, salary)
as
(
    select id avg(salary) as averagesalary from temp group by id
 )   
  select id from temp1 inner join on temp.id=temp1.id where salary>averagesalary  select * from emp e, (select dept,avg(sal) avg_sal from emp group by dept) e1 where e.dept=e1.dept and e.sal > e1.avg_sa

No comments:

Followers

Link