mysql常用语句

编辑于 2021-05-14 10:06:58 阅读 971

增删改查

-- 查询
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]

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验