HP Neoview SQL Reference Manual page 159

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

SECRETARY
...
Select from three tables, group the rows by job code and (within job code) by department
number, and order the groups by the maximum salary of each group:
SELECT E.jobcode, E.deptnum, MIN (salary), MAX (salary)
FROM persnl.employee E,
persnl.dept D, persnl.job J
WHERE E.deptnum = D.deptnum AND E.jobcode = J.jobcode
AND E.jobcode IN (900, 300, 420)
GROUP BY E.jobcode, E.deptnum
ORDER BY 4;
JOBCODE
DEPTNUM
-------
-------
900
1500
900
2500
...
300
3000
900
2000
...
300
3200
420
4000
...
--- 16 row(s) selected.
Only job codes 300, 420, and 900 are selected. The minimum and maximum salary for the
same job in each department are computed, and the rows are ordered by maximum salary.
Select from two tables that have been joined by using an INNER JOIN on matching part
numbers:
SELECT OD.*, P.*
FROM sales.odetail OD INNER JOIN sales.parts P
ON OD.partnum = P.partnum;
Order/Num
Part/Num
----------
--------
------------------
400410
212
PCSILVER, 20 MB
500450
212
PCSILVER, 20 MB
100210
244
PCGOLD, 30 MB
800660
244
PCGOLD, 30 MB
...
...
...
--- 72 row(s) selected.
Select from three tables and display them in employee number order. Two tables are joined
by using a LEFT JOIN on matching department numbers, then an additional table is joined
on matching jobcodes:
SELECT empnum, first_name, last_name, deptname, location, jobdesc
FROM employee e LEFT JOIN dept d ON e.deptnum = d.deptnum
LEFT JOIN job j ON e.jobcode = j.jobcode
ORDER BY empnum;
Suppose that the JOB_CORPORATE table has been created from the JOB table by using the
CREATE LIKE statement. Form the union of these two tables:
SELECT * FROM job UNION SELECT * FROM job_corporate;
JOHN
(EXPR)
(EXPR)
-----------
-----------
17000.00
18000.00
19000.00
32000.00
22000.00
18000.10
Unit/Price
Qty/Ord
Part/Num
------------
----------
------------
-----------
2450.00
12
2500.00
3525
2500.00
2500.00
3525
3500.00
3000.00
4426
3000.00
3000.00
4426
...
...
...
...
CHOU
28000.00
17000.00
18000.00
32000.00
32000.00
33000.10
36000.00
Part Description
--------
212
8
212
3
244
6
244
...
PRICE
Qty/Avail
SELECT Statement
159

Advertisement

Table of Contents
loading

Table of Contents