W5 DBMS Chapter07
W5 DBMS Chapter07
PRODUCT_MAST
PRODUCT COMPANY QTY RATE COST
SELECT AVG(COST) Item1 Com1 2 10 20
FROM PRODUCT_MAST; Item2 Com2 3 25 75
Item3 Com1 2 30 60
Item4 Com3 5 10 50
Item5 Com2 2 20 40
Item3 Com1 2 30 60
Item4 Com3 5 10 50
Item5 Com2 2 20 40
Item3 Com1 2 30 60
Item4 Com3 5 10 50
Item5 Com2 2 20 40
Output:
OrederID Aver
Output Max
10248 12.3 15
10249 5,5 8
10250 14.3 20
10251 5 8
10252 9 9
Copyright © 2017 Ramez Elmasri and Shamkant B. Navathe Slide 7- 20
Copyright © 2017 Ramez Elmasri and Shamkant B. Navathe Slide 7- 21
Use of WITH
SQL WITH clause allows you to give a sub-
query block a name, which can be referenced in
several places within the main SQL query.
The WITH clause allows a user to define a table
that will only be used in a particular query.
Used for convenience to create a temporary
“View” and use that immediately in a query
WITH clause is not supported by all database
system
some statement_list.
Second considers a search_condition instead of variable
002 Sahil EC M
004 Shelley CS F
Anann
005 CS F
ya
Output
EXEC procedure_name;