SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE emp ( id SERIAL PRIMARY KEY, name varchar(50), age int, depart text ); INSERT INTO emp (name, age, depart) VALUES ('tim', 22, 'it'), ('masha', 18, 'striptiz'), ('dasha', 23, 'resnici'); INSERT INTO emp (name, age, depart) VALUES ('vadim', 21, 'it'); select * from emp; select * from emp where age > 20; select * from emp order by age; SELECT COUNT(*) from emp; SELECT ROUND(AVG(age),2) as mean_age from emp; SELECT depart, COUNT(*) FROM emp GROUP BY depart; SELECT depart FROM emp GROUP BY depart HAVING count(*) > 1; SELECT depart, count(*) FROM emp GROUP BY depart; UPDATE emp SET name = 'vasya' WHERE name = 'vadim'; SELECT * from emp e1 JOIN emp e2 ON e1.depart = e2.depart and e1.id < e2.id; SELECT * FROM emp e JOIN (SELECT depart, COUNT(*) FROM emp GROUP BY depart) d ON e.depart = d.depart; CREATE INDEX name_idx ON emp(id); CREATE OR REPLACE FUNCTION func(emp_id INT) RETURNS VARCHAR AS $$ BEGIN RETURN (SELECT name FROM emp WHERE id = emp_id); END; $$ LANGUAGE plpgsql; SELECT func(1) BEGIN; SELECT * from emp; COMMIT;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear