以下是一些MySQL中经典的SQL写法:
创建表:
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);
插入数据:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
更新数据:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
删除数据:
DELETE FROM table_name
WHERE condition;
查询数据:
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column_name;
连接表:
SELECT column1, column2, ...
FROM table1
JOIN table2 ON table1.column_name = table2.column_name;
使用聚合函数:
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
分组数据:
SELECT column1, column2, ..., COUNT(column_name)
FROM table_name
GROUP BY column1, column2, ...;
使用子查询:
SELECT column1, column2, ...
FROM table_name
WHERE column_name IN (SELECT column_name FROM table_name WHERE condition);
使用临时表:
CREATE TEMPORARY TABLE temp_table_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
这些只是MySQL中一些经典的SQL写法,根据实际需求和具体情况,可能会有更多的写法和技巧。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站