sql between scrpts
TRANSCRIPT
-
7/27/2019 SQL Between scrpts
1/5
Between
SELECT *
FROM PRODUCT
WHERE PRICE BETWEEN 0.00 AND 1.00;
NOT BETWEEN
P_Code P_Name P_Description P_Quant_In_Stock P_Reorder_Quant P_Weight P_Price
W12 Small widget 3mm round widget blue striped 4 2 12.50 0.33
Greater than
SELECT *
FROM PRODUCT
Where P_Reorder_Quant
-
7/27/2019 SQL Between scrpts
2/5
*********** B17 ****************************************************
Display details of products whose Reorder quantity is more than 2 and Quantity in Stock is
more than 5
SELECT *
FROM Product
WHERE P_Reorder_Quant > 2
AND P_Quant_In_Stock >= 5;
-- Stage 1: Display details of products and suppliers
Select P_Name as Products,supplier.S_Name from product
Inner join poitem
On product.p_code=poitem.p_code
Inner join Purchaseorder
On purchaseorder.po_no=poitem.po_no
Inner join supplier
On supplier.s_no=purchaseorder.s_no;
P_Code P_Name P_Description P_Quant_In_Stock P_Reorder_Quant P_Weight P_Price
b1345 Nails 2mm Straight 10 4 10.00 0.70
X8945 Couplings 2mm White 30 10 15.00 0.90
-
7/27/2019 SQL Between scrpts
3/5
30.
-- Run the instruction and check your results.
SELECT *
FROM emp
WHERE job IN ('SALESMAN', 'MANAGER')
AND deptno = 30;
-- Stage 3: Display details of those salesmen and managers in dept 30
-- whose salary is greater than or equal to 1,500.
SELECT *
FROM emp
WHERE job IN ('SALESMAN', 'MANAGER')
AND deptno = 30
AND sal >= 1500;
/*
*********** B18 ****************************************************
Display the employee number, current job and salary of all those who work
in Department 30, with the output in ascending salary order. As before,
you may wish to write and test your instruction in a number of stages.
*/
SELECT empno, job, sal
FROM emp
WHERE deptno=30
ORDER BY sal ASC;
-- ASC is optional as it is the default
/*
*********** B19 ****************************************************
-
7/27/2019 SQL Between scrpts
4/5
Display the employee name and current job of all those who work in
Department 30, with the output in descending salary order
*/
SELECT ename, job
FROM emp
WHERE deptno=30
ORDER BY sal DESC;
-- Check carefully as the sorted column is not being displayed.
/*
*********** B20 ****************************************************
Display the employee name, current job and salary of all those who work
in Department 30, with the output in descending salary order within each
job.
*/
SELECT ename, job, sal
FROM emp
WHERE deptno=30
ORDER BY job, sal DESC;
-- *** OR***
SELECT ename, job, sal
FROM emp
WHERE deptno=30
ORDER BY job ASC, sal DESC;
/*
The question asked for the selected data to be output in descending
salary order within each job. Does this influence the best order for
displaying the columns? Can you suggest a better solution?
SELECT job, sal, ename
FROM emp
-
7/27/2019 SQL Between scrpts
5/5
WHERE deptno=30
ORDER BY job ASC, sal DESC;
*/
/*
*********** B21 ****************************************************
Display employee details for departments 10 and 30, in name order, within
each department. Display the columns in the most appropriate order.
*/
SELECT * FROM emp
WHERE DEPTNO IN (10, 30)
ORDER BY DEPTNO, ENAME;
-- Normal to display columns (left to right) in order of sorting
-- requirements.
SELECT deptno, ename, sal FROM emp
WHERE DEPTNO IN (10, 30)
ORDER BY DEPTNO, ENAME;
--14/10/08