SQL쿼리문 정리
CREATE TABLE Person (
id int,
name varchar(50),
age int NOT NULL,
gender varchar(10),
);
SELECT * FROM Person;
SELECT name, age FROM Person;
SELECT DISTINCT name, age FROM Person;
SELECT * FROM Person LIMIT 10;
SELECT * FROM Person OFFSET 5 LIMIT 5;
SELECT * FROM Person WHERE id = 1;
WHERE age > 18;
WHERE age >= 18;
WHERE age < 18;
WHERE age <= 18;
WHERE age != 18;
SELECT * FROM Person WHERE age BETWEEN 10 AND 20;
WHERE name like '%A%';
WHERE name like binary '%A%';
WHERE name like 'A%';
WHERE name like binary 'A%';
WHERE name like '%A';
WHERE name like binary '%A';
WHERE id in (1, 2);
WHERE gender='male' AND age > 25;
WHERE gender='male' OR age > 25;
WHERE NOT gender='male';
WHERE age is NULL;
WHERE age is NOT NULL;
SELECT * FROM Person order by age;
SELECT * FROM Person ORDER BY age DESC;
INSERT INTO Person VALUES ('Jack', '23', 'male');
UPDATE Person SET age = 20 WHERE id = 1;
UPDATE Person SET age = age * 1.5;
DELETE FROM Person;
DELETE FROM Person WHERE age < 10;
SELECT MIN(age) FROM Person;
SELECT MAX(age) FROM Person;
SELECT AVG(age) FROM Person;
SELECT SUM(age) FROM Person;
SELECT COUNT(*) FROM Person;
SELECT gender, COUNT(*) as count FROM Person GROUP BY gender;
SELECT gender, COUNT('gender') as count FROM Person GROUP BY gender HAVING count > 1;
SELECT name
FROM Book
LEFT JOIN Publisher
ON Book.publisher_id = Publisher.id
WHERE Book.id=1;
SELECT *
FROM Book
WHERE Book.publisher_id = 1;