STAND UP STRONGER
로그인
STAND UP STRONGER
로그인
230328 SQL
허크
·
2023년 3월 28일
팔로우
0
section_2
정리필요
0
SQL 기본 문법
SQL Select
SELECT * FROM Customers;
SELECT City FROM Customers;
SELECT DISTINCT Country FROM Customers;
SQL Where
SELECT * FROM Customers
WHERE City = 'Berlin';
SELECT * FROM Customers
WHERE NOT CIty = 'Berlin';
SELECT * FROM Customers
WHERE CustomerID = 32;
SELECT * FROM Customers
WHERE City = 'Berlin'
AND PostalCode = 12209;
SELECT * FROM Customers
WHERE City = 'Berlin'
OR City = 'London';
SQL Order By
SELECT * FROM Customers
ORDER BY City;
SELECT * FROM Customers
ORDER BY City DESC;
SELECT * FROM Customers
ORDER BY Country, City;
SQL Insert
INSERT INTO Customers (
CustomerName,
Address,
City,
PostalCode,
Country )
VALUES (
'Hekkan Burger',
'Gateveien 15',
'Sandnes',
'4306',
'Norway');
SQL Null
SELECT * FROM Customers
WHERE PostalCode IS NULL;
SELECT * FROM Customers
WHERE PostalCode IS NOT NULL;
SQL Update
UPDATE Customers
SET City = 'Oslo';
UPDATE Customers
SET City = 'Oslo'
WHERE Country = 'Norway';
UPDATE Customers
SET City = 'Oslo',
Country = 'Norway'
WHERE CustomerID = 32;
SQL Delete
DELETE FROM Customers
WHERE Country = 'Norway';
DELETE FROM Customers;
SQL Functions
SELECT MIN(Price)
FROM Products;
SELECT MAX(Price)
FROM Products;
SELECT COUNT(*)
FROM Products
WHERE Price = 18;
SELECT AVG(Price)
FROM Products;
SELECT SUM(Price)
FROM Products;
SELECT Like
SELECT * FROM Customers
WHERE City LIKE 'a%';
SELECT * FROM Customers
WHERE City LIKE '%a';
SELECT * FROM Customers
WHERE City LIKE '%a%';
SELECT * FROM Customers
WHERE City LIKE 'a%b';
SELECT * FROM Customers
WHERE City NOT LIKE 'a%';
SQL Wildcards
SELECT * FROM Customers
WHERE City LIKE '_a%';
SELECT * FROM Customers
WHERE City LIKE '[acs]%';
SELECT * FROM Customers
WHERE City LIKE '[a-f]%';
SELECT * FROM Customers
WHERE City LIKE '[!acf]%';
SQL In
SELECT * FROM Customers
WHERE Country IN ('Norway','France');
SELECT * FROM Customers
WHERE Country NOT IN ('Norway', 'France');
SQL BETWEEN
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;
SELECT * FROM Products
WHERE ProductName BETWEEN 'Geitost' AND 'Pavlova';
SQL Alias
SELECT CustomerName,
Address,
PostalCode AS Pno
FROM Customers;
SELECT *
FROM Customers AS Consumers;
SQL JOIN
SELECT *
FROM Orders
LEFT JOIN Customers
ON Orders.CustomerID = Customers.CustomerID;
SELECT *
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
SELECT *
FROM Orders
RIGHT JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
SQL Group By
SELECT COUNT (CustomerID),
Country
FROM Customers
GROUP BY Country;
SELECT COUNT (CustomerID),
Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;
SQL Database
ALTER TABLE Persons
ADD Birthday DATE;
ALTER TABLE Persons
DROP COLUMN Birthday;
허크
codestates seb 44th // 다크모드로 보는걸 추천드립니다
팔로우
이전 포스트
230328 데일리코딩
다음 포스트
0719 ddd
0개의 댓글
댓글 작성