querys new
querys new
select min(sal) as 'second minimum sal' from EMP where sal > (select min(sal) from EMP);
second minimum sal
2000
select dno,count( dno),max(sal) from EMP t group by dno having 1 < count(t.dno) ;
dno count( dno) max(sal)
10 2 2500
20 2 2000
select max(sal) ‘second max sal’ from EMP where sal not in (select max(sal) from EMP);
second max sal’
2500
eno dname
7369 Research
7499 Sales
7521 Sales
7566 Research
7654 Sales
select EMP.eno, dept.dname from EMP right JOIN dept ON EMP.dno = dept.dno;
eno dname
7782 Accounting
7839 Accounting
7934 Accounting
7369 Research
7566 Research
7788 Research
7876 Research
7902 Research
7499 Sales
7521 Sales
7654 Sales
7698 Sales
7844 Sales
7900 Sales
NULL Operations
select EMP.eno,dept.dname from EMP cross JOIN dept -- ON EMP.dno = dept.dno;
eno dname
7369 Operations
7369 Sales
7698 Research
7698 Accounting
7782 Operations
7782 Sales
7876 Research
7876 Accounting
select dno, count(distinct dno) ,job, count(job) from EMP group by dno,job
create table Sailors (sid Integer primary key , sname Text, rating Integer, age Integer);
desc Sailors;
create table Boats (bid Integer primary key, bname Text, color Text);
desc Boats;
Field Type Null Key Default Extra
bid int NO PRI NULL
bname text YES NULL
color text YES NULL
create table Reserves (sid Integer, bid integer, day Date,FOREIGN KEY (sid) REFERENCES
Sailors(sid),FOREIGN KEY (bid) REFERENCES Boats(bid));
desc Reserves;
select distinct b.color from Boats b,Reserves r,Sailors s where b.bid=r.bid and r.sid=s.sid and
sname='lubber'
color
red
green
black
yellow
(ii) Find the names of sailors who have reserved at least one
Boat
select distinct sname from Sailors s, Reserves r where r.sid=s.sid;
sname
lubber
ramu
laxman
(iii) Find the names of sailors who have reserved a red or green
Boat
SELECT R.sid FROM Boats B, Reserves R WHERE R.bid = B.bid AND B.color = ‘red’
UNION
SELECT R2.sid FROM Boats B2, Reserves R2 WHERE R2.bid = B2.bid AND B2.color = ‘green’
(iv) Find the names of the sailors who have reserved both a
Red boat and a Green boat.
SELECT R.sid FROM Boats B, Reserves R WHERE R.bid = B.bid AND B.color = ‘red’ INTERSECT
SELECT R2.sid FROM Boats B2, Reserves R2 WHERE R2.bid = B2.bid AND B2.color = ‘green’
SELECT S.sname FROM Sailors S WHERE NOT EXISTS ( ( SELECT B.bid FROM Boats B) EXCEPT
( SELECT R.bid FROM Reserves R WHERE R.sid = S.sid ) )
1.select round((sin(30)),0);
2.The TRIM() function is a powerful tool used to remove unwanted characters from the beginning, end,
or both ends of a string. This function is particularly useful in data cleansing tasks, ensuring that strings
are free from leading and trailing whitespace or specified characters.
Key Uses of the TRIM() Function:
One of the most common applications is to clean up user input by removing excess spaces.
TRIM() can strip unwanted prefixes or suffixes from data fields, aiding in maintaining consistent and
clean data.
Before storing or displaying data, TRIM() helps in standardizing strings to remove any unnecessary
padding.
Syntax:
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM ] str)
Arguments:
Name Description
BOTH Removes characters from both the left and right sides of the string.
LEADING Removes characters only from the left side of the string.
TRAILING Removes characters only from the right side of the string.
remstr The string to be removed from the specified side(s) of the original string.
str The actual string from which characters are to be removed.