-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexample.sql
More file actions
32 lines (29 loc) · 870 Bytes
/
example.sql
File metadata and controls
32 lines (29 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Declare table schemas
create table dept(
deptno integer,
dname varchar,
loc varchar,
constraint pk_dept primary key (deptno)
);
create table emp(
empno integer,
ename varchar,
job varchar,
mgr integer,
hiredate date,
sal integer,
comm integer,
deptno integer,
constraint pk_emp primary key (empno),
constraint no_sal check (sal > 0)
);
-- Declare function signatures
declare scalar function fund(varchar) returns float;
declare aggregate function my_avg(integer) returns float;
-- Define queries (There should only be two!)
select fund(dname) from dept as d join (
select deptno, my_avg(sal) as avg_sal
from emp
group by deptno
) as s on d.deptno - s.deptno = 0;
select fund(dname) from dept where deptno in (select deptno from emp);