Tugas Praktikum 3 Dengan PostgreSQL
Tugas Praktikum 3 Dengan PostgreSQL
PROGRAM DIPLOMA III TEKNIK INFORMATIKA POLITEKNIK POS INDONESIA BANDUNG 2011
Contoh Aggregates
test=> SELECT * FROM friend ORDER BY firstname;
Penggunaan Group By
=> SELECT state, COUNT(*) -> FROM friend -> GROUP BY state;
=> SELECT state, MIN(age), MAX(age), AVG(age) -> FROM friend -> GROUP BY state -> ORDER BY 4 DESC;
Penggunaan HAVING
test=> SELECT state, COUNT(*) test-> FROM friend test-> GROUP BY state test-> HAVING COUNT(*) > 0 test-> ORDER BY state;
JOINING TABLES
=> SELECT firstname FROM friend WHERE state = 'PA';
=> CREATE TABLE employee ( (> employee_id INTEGER, (> name CHAR(30), (> hire_date DATE (> );
=> CREATE TABLE part ( (> part_id INTEGER, (> name CHAR(30), (> cost NUMERIC(8,2), (> weight FLOAT (> );
=> CREATE TABLE salesorder ( (> order_id INTEGER, (> customer_id INTEGER, -- joins to ustomer.customer_id (> employee_id INTEGER, -- joins to employee.employee_id (> part_id INTEGER, -- joins to part.part_id (> order_date DATE, (> ship_date DATE, (> payment NUMERIC(8,2) (> );
=> INSERT INTO employee VALUES ( (> 24, (> 'Lee Meyers', (> '10/16/1989' (> ); INSERT 19816 1
=> INSERT INTO part VALUES ( (> 153, (> 'Garage Door Spring', (> 6.20 (> ); INSERT 19817 1
=> INSERT INTO salesorder VALUES( (> 14673, (> 648, (> 24, (> 153, (> '7/19/1994', (> '7/28/1994', (> 18.39 (> ); INSERT 19818 1