日誌2023-04-20 14:06
【SQL】一些常用的SQL語法作者:Chris
SELECT 'cID' FROM 'students'; SELECT 'cID' ,'cName' FROM 'students'; |
SELECT DISTINCT 'cSex' FROM 'students'; |
SELECT * FROM 'students'; |
SELECT * FROM 'students' WHERE 'cSex' = 'M'; |
SELECT * FROM 'students' WHERE 'cID' > 5 AND 'cSex' = 'M'; |
SELECT * FROM 'students' WHERE 'cID' IN {1,3,5,7,9}; |
SELECT * FROM 'students' WHERE 'cBirthay' BETWEEN '1987-01-01' AND '1988-12-31'; |
SELECT * FROM 'students' WHERE 'cPhone' LIKE '0918%'; |
SELECT * FROM 'students' WHERE 'cName' LIKE '%志%'; |
SELECT * FROM 'students' ORDER BY 'cBirthay' DESC /*ASC:遞增排序(由小到大)、DESC:遞減排序(由大到小)*/ |
SELECT * FROM 'students' ORDER BY 'cSex' ASC, 'cBirthay' DESC; |
SELECT * FROM 'students' ORDER BY 'cSex' ASC, 'cBirthay' DESC LIMIT 4; |
INSERT INTO 'students' ('cName','cSex','cBirthday','cEmail','cPhone') VALUES ('李伯恩','M','1981-06-15','born@superstar.com','0929011234'); |
UPDATE 'students' SET 'cHeight'=174,'cWeight'=92 WHERE 'cID'=11; |
DELETE FROM 'students' WHERE 'cID'>11; |
刪除需使用判斷式,否則會把整個資料表給刪除 |
DELETE FROM 'students' WHERE 'cID' IN {11}; |
刪除需使用判斷式,否則會把整個資料表給刪除 |
2023-04-26 19:40Chris:https://www.mysql.tw/2015/04/super-keycandidate-keyprimary.html