CREATE TABLE Employee ( EmpId INTEGER NULL, EmpName VARCHAR(255) NULL, EmpBOD DATE, EmpJoiningDate DATE, PrevExperience INTEGER NULL, Salary int NULL, Address VARCHAR(255) NULL ); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(1,'Kieran Wilson','Aug 25, 2019','Feb 17, 2020',9,42655,'P.O. Box 653, 5711 Metus Street'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(2,'Keefe Byrd','Jul 6, 2019','May 13, 2020',4,51957,'3117 Interdum Rd.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(3,'Brendan James','Apr 19, 2020','Mar 28, 2020',6,10816,'3519 Nunc Ave'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(4,'Jerry Beard','Apr 13, 2020','Jun 7, 2020',3,74119,'P.O. Box 536, 5943 Tellus St.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(5,'Fitzgerald Bean','Apr 23, 2019','Nov 15, 2018',6,81052,'123-5228 Mauris Street'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(6,'Amir Salinas','Aug 22, 2020','Aug 13, 2020',9,58658,'732 In Street'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(7,'Justin Bender','Sep 28, 2020','May 3, 2020',10,66617,'148 Maecenas Rd.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(8,'Colorado Cohen','Nov 22, 2019','May 22, 2020',3,15364,'882-1776 Vivamus Rd.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(9,'Dolan Stokes','Apr 23, 2020','Mar 13, 2019',8,25884,'P.O. Box 844, 1589 Elit, Av.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(10,'Byron Clements','Jul 19, 2019','Apr 27, 2020',3,17807,'P.O. Box 413, 8630 Vitae, St.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(11,'Russell Griffin','Feb 2, 2019','Jun 25, 2019',3,64406,'Ap #279-8301 Magna Rd.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(12,'Brady Carney','Dec 19, 2019','May 24, 2020',10,14806,'Ap #278-9852 Nibh. Street'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(13,'Keefe Klein','Aug 13, 2020','Aug 16, 2019',3,88833,'9814 Egestas Avenue'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(14,'Walker Simon','Feb 25, 2020','Jan 24, 2019',6,56364,'2335 Aliquam Ave'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(15,'Geoffrey Nunez','Jun 17, 2019','Jun 6, 2019',10,37364,'912-7721 Mus. Av.'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(16,'Myles Mcknight','Apr 15, 2020','Mar 7, 2020',9,91041,'477-2321 Commodo Avenue'); INSERT INTO Employee( EmpId , EmpName , EmpBOD , EmpJoiningDate , PrevExperience , Salary , Address ) VALUES(17,'Cadman Justice','Jul 9, 2019','Dec 29, 2019',2,34840,'P.O. Box 529, 8813 Proin Rd.'); SELECT * FROM Employee; SELECT empname, salary FROM Employee WHERE salary >50000; SELECT empname, prevexperience, salary FROM Employee WHERE prevexperience > 3; alter table Employee add empjoinyear integer generated always as (extract (year from Empjoiningdate)) stored; SELECT empjoinyear, round(AVG(salary),2)FROM Employee Group by empjoinyear; alter table Employee add empjoinmonth integer generated always as (extract (month from Empjoiningdate)) stored; SELECT empjoinmonth, round(AVG(salary),2)FROM Employee Group by empjoinmonth;
Write, Run & Share PostgreSQL queries online using OneCompiler's PostgreSQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for PostgreSQL. Getting started with the OneCompiler's PostgreSQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose database as 'PostgreSQL' and start writing queries to learn and test online without worrying about tedious process of installation.
PostgreSQL is a open source relational database system and is also knows as Postgres.
CREATE command is used to create a table, schema or an index.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
....);
ALTER command is used to add, modify or delete columns or constraints from the database table.
ALTER TABLE Table_name ADD column_name datatype;
TRUNCATE command is used to delete the data present in the table but this will not delete the table.
TRUNCATE table table_name;
DROP command is used to delete the table along with its data.
DROP TABLE table_name;
RENAME command is used to rename the table name.
ALTER TABLE table_name1 RENAME to new_table_name1;
INSERT Statement is used to insert new records into the database table.
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Select statement is used to select data from database tables.
SELECT column1, column2, ...
FROM table_name;
UPDATE statement is used to modify the existing values of records present in the database table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE statement is used to delete the existing records present in the database table.
DELETE FROM table_name where condition;