Last active
June 22, 2020 10:10
-
-
Save megpay/6858954c48239c2b85721fac686967b4 to your computer and use it in GitHub Desktop.
DB2 Practice - Some samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Create table syntax with an auto-incremented field. */ | |
DROP TABLE NewEmployees; | |
/* Note the auto increment syntax. It is slightly different. */ | |
CREATE TABLE NewEmployees ( | |
ID INT GENERATED BY DEFAULT AS IDENTITY | |
(START WITH 100 INCREMENT BY 10), | |
first_name VARCHAR(50), | |
last_name VARCHAR(50), | |
salary INT, | |
PRIMARY KEY(ID) | |
); | |
INSERT INTO NewEmployees (first_name, last_name, salary) | |
VALUES ('Jane', 'Doe', '50000'); | |
INSERT INTO NewEmployees (first_name, last_name, salary) | |
VALUES ('Janelle', 'Doe', '55000'); | |
INSERT INTO NewEmployees (first_name, last_name, salary) | |
VALUES ('James', 'Doe', '60000'); | |
SELECT SUM(salary) FROM NewEmployees; | |
SELECT AVG(salary) FROM NewEmployees; | |
SELECT ID, salary FROM NewEmployees WHERE salary < (SELECT AVG(salary) FROM NewEmployees); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment