mysql常用语句
编辑于 2021-05-14 18:06:58 阅读 1358
增删改查
-- 查询
SELECT `title`, `content` FROM `article` WHERE `id` > 0;
-- 新增
INSERT INTO `article`(`title`, `content`) VALUES('ttt','ccc');
INSERT INTO `article` VALUES(1, 'ttt','ccc');#省略字段名
INSERT INTO `article` (`title`, `content`) VALUES('ttt','ccc'), ('ttt2','ccc2');#批量插入
INSERT INTO `article` SET `title`='ttt', `content`='ccc' WHERE `id`=1;#使用update 语句的set方式插入数据
-- 更新
UPDATE `article` SET `title`='ttt2', `content`='ccc2' WHERE `id`=1;
-- 删除
DELETE FROM `article` WHERE `id`=1;
复杂的
--INSERT和SELECT一起用
INSERT INTO `order_goods` (`user_id`, `goods_id`, `title`, `prize`, `create_time`) SELECT ?, `id`, `title`, `prize`, ? FROM `goods` WHERE `id` = ?;#[1,2,3]