Temporal Table Oracle Vs SQL Server , How to and history - oracle

The following code denotes both Sql Server and Oracle both to create a temporal Solution.
For Oracle the following article is the basis.
---/// Temporal Table SQL Server ///---
CREATE TABLE dbo.Employee(
EMPNO INT
,ENAME VARCHAR(10)
,JOB VARCHAR(9)
,MGR INT
,HIREDATE DATE
,SAL NUMERIC(7,2)
,COMM NUMERIC(7,2)
,DEPTNO INT
CONSTRAINT EMP_PK PRIMARY KEY (EMPNO)
,SysStartTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL
,SysEndTime datetime2 GENERATED ALWAYS AS ROW END NOT NULL
,PERIOD FOR SYSTEM_TIME (SysStartTime,SysEndTime))
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.EmployeeHistory, DATA_CONSISTENCY_CHECK = ON));
INSERT INTO dbo.Employee (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)values
(7369, 'SMITH', 'CLERK', 7902, '02-MAR-1970', 8000, NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '20-MAR-1971', 1600, 3000, 30),
(7521, 'WARD', 'SALESMAN', 7698, '07-FEB-1983', 1250, 5000, 30),
(7566, 'JONES', 'MANAGER', 7839, '02-JUN-1961', 2975, 50000, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, '28-FEB-1971', 1250, 14000, 30),
(7698, 'BLAKE', 'MANAGER', 7839, '01-JAN-1988', 2850, 12000, 30),
(7782, 'CLARK', 'MANAGER', 7839, '09-APR-1971', 2450, 13000, 10),
(7788, 'SCOTT', 'ANALYST', 7566, '09-DEC-1982', 3000, 1200, 20),
(7839, 'KING', 'PRESIDENT', NULL, '17-JUL-1971', 5000, 1456, 10),
(7844, 'TURNER', 'SALESMAN', 7698, '08-AUG-1971', 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, '12-MAR-1973', 1100, 0, 20),
(7900, 'JAMES', 'CLERK', 7698, '03-NOV-1971', 950, 0, 30),
(7902, 'FORD', 'ANALYST', 7566, '04-MAR-1961', 3000, 0, 20),
(7934, 'MILLER', 'CLERK', 7782, '21-JAN-1972', 1300, 0, 10)
SELECT * FROM Employee
SELECT * FROM EmployeeHistory --Would return 0 rows.
UPDATE EMPLOYEE
SET SAL=SAL+2000
WHERE EMPNO=7369
SELECT * FROM Employee
SELECT * FROM EmployeeHistory --Would return 1 rows. prior to change.
UPDATE EMPLOYEE
SET SAL=SAL+2000
WHERE EMPNO=7369
SELECT * FROM Employee
SELECT * FROM EmployeeHistory --Would return 2 rows. prior to change.
--if you want to check the list of changes which have happend you could simply query the history table .
SELECT * FROM EmployeeHistory WHERE EMPNO = 7396
union all
SELECT * FROM Employee WHERE EMPNO = 7396
ORDER BY SysStartTime DESC
---/// Temporal Table Oracle ///---
---/// ORACLE (ASSUME AUTOCOMMIT IS ON). ///---
CREATE TABLESPACE STATIC_DATA DATAFILE 'static_data.dbf' SIZE 10m AUTOEXTEND ON MAXSIZE 1g ;
CREATE TABLESPACE STATIC_ARCHIVE DATAFILE 'static_archive.dbf' SIZE 10m AUTOEXTEND ON MAXSIZE 1g ;
CREATE FLASHBACK ARCHIVE STATIC_ARCHVIE_FB TABLESPACE STATIC_ARCHIVE QUOTA 1 G RETENTION 7 YEAR; --7 YEARS RETENTION.
CREATE TABLE TEST.Employee(
EMPNO INT
,ENAME VARCHAR(10)
,JOB VARCHAR(9)
,MGR INT
,HIREDATE DATE
,SAL NUMERIC(7,2)
,COMM NUMERIC(7,2)
,DEPTNO INT
CONSTRAINT EMP_PK PRIMARY KEY (EMPNO)
)
TABLESPACE STATIC_DATA;
ALTER TABLE TEST.Employee ADD PERIOD FOR History;
ALTER TABLE TEST.Employee FLASHBACK ARCHIVE STATIC_ARCHVIE_FB;
INSERT INTO TEST.Employee (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)values
(7369, 'SMITH', 'CLERK', 7902, '02-MAR-1970', 8000, NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '20-MAR-1971', 1600, 3000, 30),
(7521, 'WARD', 'SALESMAN', 7698, '07-FEB-1983', 1250, 5000, 30),
(7566, 'JONES', 'MANAGER', 7839, '02-JUN-1961', 2975, 50000, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, '28-FEB-1971', 1250, 14000, 30),
(7698, 'BLAKE', 'MANAGER', 7839, '01-JAN-1988', 2850, 12000, 30),
(7782, 'CLARK', 'MANAGER', 7839, '09-APR-1971', 2450, 13000, 10),
(7788, 'SCOTT', 'ANALYST', 7566, '09-DEC-1982', 3000, 1200, 20),
(7839, 'KING', 'PRESIDENT', NULL, '17-JUL-1971', 5000, 1456, 10),
(7844, 'TURNER', 'SALESMAN', 7698, '08-AUG-1971', 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, '12-MAR-1973', 1100, 0, 20),
(7900, 'JAMES', 'CLERK', 7698, '03-NOV-1971', 950, 0, 30),
(7902, 'FORD', 'ANALYST', 7566, '04-MAR-1961', 3000, 0, 20),
(7934, 'MILLER', 'CLERK', 7782, '21-JAN-1972', 1300, 0, 10)
SELECT * FROM TEST.Employee
-- ??? any Equivalent in Oracle for this -> SELECT * FROM EmployeeHistory .
UPDATE TEST.Employee
SET SAL=SAL+2000
WHERE EMPNO=7369
UPDATE TEST.Employee
SET SAL=SAL+1000
WHERE EMPNO != 7369
SELECT * FROM TEST.Employee --//Would return the current dataset.
SELECT employee_id FROM TEST.Employee AS OF PERIOD FOR history 'Date_to_be_replaced_with_Scn_in_your_database'
--// The above would retun the data before update all records.
Question 1: I can see the changes only at a point in time. If the record is updated multiple times in a day how do i get the changes to show the history?
Question 2: Is flashback not a temporary table and may get purged when certain events occur in db?
I tried querying between specific date ranges but the query is only point in time and would not give me all the history of the records like sql server.
I will if this does not work need to write trigger on each static table and insert it to my own history table. Trying to avoid triggers.

If you're looking at a complete history, then flashback data archive is probably the solution you want to be exploring, combined with the VERSIONS BETWEEN clause. For example, for a (single) row in the DEPT table you could write
SQL> SELECT deptno, dname,
2 VERSIONS_STARTTIME
3 ,VERSIONS_XID
4 ,VERSIONS_OPERATION
5 FROM dept
6 VERSIONS BETWEEN TIMESTAMP
7 SYSTIMESTAMP - INTERVAL '20:00' MINUTE TO SECOND
8 AND SYSTIMESTAMP
9 WHERE deptno = 10;
DEPTNO DNAME VERSIONS_STARTTIME VERSIONS_XID V
--------- -------------- ---------------------- ---------------- -
10 UNKNOWN 06-MAY-20 11.53.45 PM 0200100060040000 U
10 MONEY GRABBERS 06-MAY-20 11.53.36 PM 0600050065040000 U
10 FINANCE 06-MAY-20 11.53.24 PM 09000D001D050000 U
10 BEAN COUNTERS 06-MAY-20 11.53.12 PM 01001A00EA030000 U
10 ACCOUNTING
Here's a video explaining the "behind the scenes" on FDA
https://youtu.be/qIs2UPIodQg
and if you do end up going down the trigger route, I've got an implementation that lets you auto-generate them for tables here
https://github.com/connormcd/audit_utility

Related

Hierarchical Queries inside Join

I'm facing one annoying problema and I would like some help.
This is the situation.
CREATE TABLE tree_hierarchy (
id NUMBER (20)
,parent_id NUMBER (20)
);
CREATE TABLE tree_information (
id NUMBER (20)
,some_text VARCHAR(20)
,tree_id NUMBER (20)
);
INSERT INTO tree_hierarchy (id, parent_id) VALUES (2, null);
INSERT INTO tree_hierarchy (id, parent_id) VALUES (4, 2);
INSERT INTO tree_hierarchy (id, parent_id) VALUES (9, 4);
INSERT INTO tree_hierarchy (id, parent_id) VALUES (20, null);
INSERT INTO tree_hierarchy (id, parent_id) VALUES (40, 20);
INSERT INTO tree_hierarchy (id, parent_id) VALUES (90, 40);
INSERT INTO tree_information (id, some_text, tree_id) VALUES (10,'Some teste', 2);
INSERT INTO tree_information (id, some_text, tree_id) VALUES (11,'Other tree', 20);
And i would like to do something like this.
SELECT hier.*
FROM tree_information Ti
JOIN (
SELECT
id,
parent_id
FROM tree_hierarchy th
where connect_by_isleaf = 1
START WITH th.id = ti.tree_id
CONNECT BY PRIOR th.id = th.parent_id
) hier on 1=1;
but ti.tree_id is not visible inside the select.
If I change the start with condition for
START WITH th.parent_id is null
Will stay wrong.
Someone has idea how to solve this situation ?
I would appreciate if you provide expected result explicitly.
My best guess is:
SELECT hier.*, ti.*
FROM tree_information Ti
JOIN (
SELECT
id,
parent_id,
connect_by_root th.id as tree_id
FROM tree_hierarchy th
where connect_by_isleaf = 1
START WITH th.id in ( select tii.tree_id from tree_information Tii)
CONNECT BY PRIOR th.id = th.parent_id
) hier on ti.tree_id = hier.tree_id;
ID PARENT_ID TREE_ID ID SOME_TEXT TREE_ID
9 4 2 10 Some teste 2
90 40 20 11 Other tree 20

Merge statement

I am looking into merge statements, but I can not figure out the syntax.
Let's say I have these tables
CREATE TABLE employee (
employee_id NUMBER(5),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
dept_no NUMBER(2),
salary NUMBER(10));
INSERT INTO employee VALUES (1, 'Dan', 'Morgan', 10, 100000);
INSERT INTO employee VALUES (2, 'Helen', 'Lofstrom', 20, 100000);
INSERT INTO employee VALUES (3, 'Akiko', 'Toyota', 20, 50000);
INSERT INTO employee VALUES (4, 'Jackie', 'Stough', 20, 40000);
INSERT INTO employee VALUES (5, 'Richard', 'Foote', 20, 70000);
INSERT INTO employee VALUES (6, 'Joe', 'Johnson', 20, 30000);
INSERT INTO employee VALUES (7, 'Clark', 'Urling', 20, 90000);
CREATE TABLE bonuses (
employee_id NUMBER, bonus NUMBER DEFAULT 100);
INSERT INTO bonuses (employee_id) VALUES (1);
INSERT INTO bonuses (employee_id) VALUES (2);
INSERT INTO bonuses (employee_id) VALUES (4);
INSERT INTO bonuses (employee_id) VALUES (6);
INSERT INTO bonuses (employee_id) VALUES (7);
COMMIT;
and just for the sake of an example I want to update all entries of bonuses with 200 * employee_id. Here is my statement. What's wrong with it?
merge into bonuses b
using
(select employee_id id, 200 bonus from employees) test
on (test.id = b.employee_id)
when matched then update set
b.bonus = test.bonus * test.employee_id
Thanks!
P.S. See also my sqlfiddle here: http://sqlfiddle.com/#!4/ff425/14
merge into bonuses b
using
(select employee_id id, 200 bonus from employee) test
on (test.id = b.employee_id)
when matched then update set
b.bonus = test.bonus * test.id;
Two minor mistakes:
1) employee instead of employees
2) test.id instead of test.employee_id

How to INSERT a DATE?

Hi I am new to Oracle and forgot how to enter a date. I have tried many variations and can't seem to get it, plus I have looked on the internet but can't find the correct example. My table is set up like this: hiredate DATE, (DATE being I assume the default input, but what is the default).
Thanks for any help.
Here's my code:
SQL> SET LINESIZE 120
SQL> SET PAGESIZE 45
SQL> SET FEEDBACK 1
SQL> SET ECHO ON
SQL>
SQL> DROP TABLE employee
2
SQL> CREAT TABLE student
SP2-0734: unknown command beginning "CREAT TABL..." - rest of line ignored.
SQL> CREATE TABLE employee
2 (
3 empno NUMBER(4)CONSTRAINT employee_empno_PK PRIMARY KEY,
4 empname VARCHAR(10),
5 job VARCHAR(10),
6 manager NUMBER(4),
7 hiredate DATE,
8 salary NUMBER(7,2),
9 commission NUMBER(7,2),
10 deptno NUMBER(2)
11 );
Table created.
SQL> INSERT INTO employee
2 VALUES(7839, 'President', NULL, 11/17/1981, 5000, NULL, 10);
INSERT INTO employee
*
ERROR at line 1:
ORA-00947: not enough values
SQL> VALUES(7839, 'President', NULL, '11/17/1978', 5000, NULL, 10);
SP2-0734: unknown command beginning "VALUES(783..." - rest of line ignored.
SQL> INSERT INTO employee
2 VALUES(7839, 'President', NULL, '11/17/1978', 5000, NULL, 10);
INSERT INTO employee
*
ERROR at line 1:
ORA-00947: not enough values
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, 11/17/1981, 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, 11/17/1981, 5000, NULL, 10)
*
ERROR at line 2:
ORA-00932: inconsistent datatypes: expected DATE got NUMBER
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, 19811117, 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, 19811117, 5000, NULL, 10)
*
ERROR at line 2:
ORA-00932: inconsistent datatypes: expected DATE got NUMBER
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '11/17/1981', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '11/17/1981', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01843: not a valid month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '1978/11/17
3 )
4 ;
ERROR:
ORA-01756: quoted string not properly terminated
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President' NULL, '1978/11/17', 5000, NULL, 10);
VALUES(7839, 'King', 'President' NULL, '1978/11/17', 5000, NULL, 10)
*
ERROR at line 2:
ORA-00917: missing comma
Hello, I am new to MySQL and forgot how to properly INSERT at DATE when using MySQL Plus. I have tried many different variations as you will be able to see and I can't seem to figure it out. I also looked on the internet but always find examples where they make there own formats. What is the correct way to insert a date when the table was created using: hiredate
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '1981/11/17', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '1981/11/17', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01861: literal does not match format string
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '1981/17/11', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '1981/17/11', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01861: literal does not match format string
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '17/11/1981', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '17/11/1981', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01843: not a valid month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '81/11/17', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '81/11/17', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01847: day of month must be between 1 and last day of month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '17/11/81', 5000, NULL, 100);
VALUES(7839, 'King', 'President', NULL, '17/11/81', 5000, NULL, 100)
*
ERROR at line 2:
ORA-01843: not a valid month
SQL> INSERT INTO employee
2 VALUES(7839, 'King, 'President', NULL, '11/17/1981', 5000, NULL, 10);
ERROR:
ORA-01756: quoted string not properly terminated
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '11/17/81', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '11/17/81', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01843: not a valid month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '17/11/81', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '17/11/81', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01843: not a valid month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '81/17/11', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '81/17/11', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01847: day of month must be between 1 and last day of month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '17/81/11', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '17/81/11', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01843: not a valid month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '81/11/17', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '81/11/17', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01847: day of month must be between 1 and last day of month
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '1981-11-17', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '1981-11-17', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01861: literal does not match format string
SQL> INSERT INTO employee
2 VALUES(7839, 'King', 'President', NULL, '17/11/1981', 5000, NULL, 10);
VALUES(7839, 'King', 'President', NULL, '17/11/1981', 5000, NULL, 10)
*
ERROR at line 2:
ORA-01843: not a valid month
You can use the TO_DATE function:
TO_DATE('11/17/1981', 'MM/DD/YYYY')
It lets you specify a date as a string and then the format that its in so Oracle can convert it into a Date.
Or you can use a date literal:
date '1981-11-17'
Dates are format sensitive in SQL. So you need to enclouse them in single quotes like
('21-Dec-2010'). If your date is not coming in the standard format then you need to convert using Single Row Conversion Function TO_DATE using the specific format model. You can find more of these syntax on my portal here
http://www.suhelsayyad.com/p/blog-page_14.html

sum of multiple columns in ORACLE

I have a table that has 97 columns, I want to sum 96 columns.
select sum(col1+col2+col3+.....+col96)
from tableA where meter_id=x;
I do not want to give all 96 column names, what is the best way to do it?
Regards,
RR
There is no way to avoid writing each column name. All you can do is curse the stupid data modeller and get busy with cut'n'paste.
In the case where there are a significant number of columns, I would look at using the data dictionary tables to help create the query by using a query like the one below:
Select column_name || '+' as column_name_list
From user_tab_columns
Where table_name = 'TABLEA'
Order by column_id
It doesn't change the world but does simplify writing one query.
You could create a virtual column that adds up your 96 columns, something like:
alter table TABLEA add (MY_TOTAL_COL NUMBER GENERATED ALWAYS AS (col1+col2+col3...) VIRTUAL);
Then your query can simply do sum(my_total_col).
You might be best to sum the columns and then put the result in Excel to do the sum of sums. Otherwise this query should do what you need:
SELECT SUM(TOTAL_SUM) FROM (
SELECT SUM(column1) AS TOTAL_SUM FROM your_table
UNION
SELECT SUM(column2) AS TOTAL_SUM FROM your_table
UNION
SELECT SUM(column3) AS TOTAL_SUM FROM your_table
);
SELECT A.consol_key,
A.amt_lcy,
B.amt_lcy,
C.amt_lcy
FROM categ A,
spec B,
stmt C;
SELECT Sum(total_sum)
FROM (SELECT Sum(amt_lcy) AS TOTAL_SUM
FROM categ
UNION
SELECT Sum(amt_lcy) AS TOTAL_SUM
FROM spec
UNION
SELECT Sum(amt_lcy) AS TOTAL_SUM
FROM stmt)
WHERE table_id NOT IN (SELECT table_id
FROM categ
WHERE txn_code = 'COR'
AND system_id <> 'AA');
It could be possible:
Using Can an SQL procedure return a table?
and the answer of Mike Meyers you could write a stored procedure using dynamic sql
sumcolumns(columnfilter,tablename,whereclause)
and use it something like
select *
from table(sumcolumns('column_name <> ''col97''','tableA','meter_id=x'))
Try using UNPIVOT as per example below (still need to specify the column list as others have noted):
with tableA as /* prototype tableA just for example */
(
select 1 meter_id, 101 col1, 10 col2, 20 col3, 30 col4, NULL col5, 101 col11, 10 col12, 20 col13, 30 col14, NULL col15, 101 col21, 10 col22, 20 col23, 30 col24, NULL col25 from dual union
select 2, 102, 40, NULL, 50, NULL, 102, 40, NULL, 50, NULL, 102, 40, NULL, 50, NULL from dual union
select 3, 103, 60, 70, 80, 90, 103, 60, 70, 80, 90, 103, 60, 70, 80, 90 from dual union
select 4, 104, 100, NULL, NULL, NULL, 104, 100, NULL, NULL, NULL, 104, 100, NULL, NULL, NULL from dual
)
, unpivoted_tableA as /* UNPIVOT tableA columns into rows */
(
select *
from tableA
unpivot include nulls
(
col_value for col_ in
(COL1,COL2,COL3,COL4,COL5,COL11,COL12,COL13,COL14,COL15,COL21,COL22,COL23,COL24,COL25)
)
)
/* main query - Sum of all columns that were unpivoted to rows */
select meter_id, sum(col_value)
from unpivoted_tableA
group by meter_id
;

Merge is not returning right data

I have 2 tables:
CREATE TABLE employee (
employee_id NUMBER(5),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
dept_no NUMBER(2),
salary NUMBER(10));
Table employee has values:
(1, 'Dan', 'Morgan', 10, 100000);
(2, 'Helen', 'Lofstrom', 20, 100000);
(3, 'Akiko', 'Toyota', 20, 50000);
(4, 'Jackie', 'Stough', 20, 40000);
(5, 'Richard', 'Foote', 20, 70000);
(6, 'Joe', 'Johnson', 20, 30000);
(7, 'Clark', 'Urling', 20, 90000);
CREATE TABLE bonuses (
employee_id NUMBER, bonus NUMBER DEFAULT 100);
Table bonuses has values:
(1,100);
(2,100);
(4,100);
(6,100);
(7,100);
And I did merge based on bonuses table:
MERGE INTO bonuses b
USING (
SELECT employee_id, salary, dept_no
FROM employee
WHERE dept_no =20) e
ON (b.employee_id = e.employee_id)
WHEN MATCHED THEN
UPDATE SET b.bonus = e.salary * 0.1
DELETE WHERE (e.salary < 40000)
WHEN NOT MATCHED THEN
INSERT (b.employee_id, b.bonus)
VALUES (e.employee_id, e.salary * 0.05)
WHERE (e.salary > 40000);
And when I
select * from bonuses;
EMPLOYEE_ID BONUS
------------------
1 100
2 10000
3 2500
4 4000
5 3500
7 9000
My question is "where is my bonuses record for employee_id #6"?
Deleted by DELETE WHERE (e.salary < 40000) statement?.
And You should probably make one of you conditions to include equality.
After all someone salary may be just 40K just like Jackie's.

Resources