Data to test:
[nchar](10) NULL,
[nchar](10) NULL,
[int] NULL
salary
· Howto get nth Highest Salary from Emp Table
= (SELECT COUNT(*) FROM emp b WHERE a.salary <= b.salary) ;
nth= (SELECT COUNT(*) FROM emp b WHERE a.salary <= b.salary) ;
· Howto delete duplicate rows from a table
autoid NOT IN
· Selectalternate rows from Emp table
AS
XYZ -5000 10
AK 10000 4
KHJ 11000 6
MAN 14000 8
· Selectnth record from Emp table
· Supposea column has some -Ve values and +Ve
values.Find the sum of -Ve numbers and the sum of the +Ve numbers.
Sum_of_negative_amount,
Sum_of_positive_amount
Suppose You
have a table
create table tbltests(id int
,id1 int)
insert into tbltests(id,id1) values
(1,2),(2,1),(3,null),(4,5),(5,4)
Table Data:
1 2
2 1
3 NULL
4 5
5 4
Fetch data like
id
id1
1
2
3
NULL
4
5
Query:
SELECT t1.id,t1.id1FROM tbltests t1WHERE NOT EXISTS(SELECT * FROM tbltests t2WHERE t2.id = t1.id1
AND t2.id1 = t1.id
AND t2.id < t2.id1)