常用sql语句总结

2021-02-27  本文已影响0人  申_9a33

1.创建表create

create table if not exists ${tablename} (${sqldata})

2.查询SELECT

2.1普通查询

SELECT * FROM ${tablename} WHERE id=?

2.2组合过滤AND,OR

SELECT * FROM ${tablename} WHERE chatId=? AND (chatType=? OR chatType=?)

2.3对搜索结果进行排序 ORDER BY

2.3.1降序DESC

SELECT * FROM ${tablename} WHERE chatId=? ORDER BY createTime DESC

2.3.2升序ASC

SELECT * FROM ${tablename} WHERE chatId=? ORDER BY createTime ASC

2.4 模糊搜索 LIKE '%xxx%'

SELECT * FROM ${tablename} WHERE chatId=? AND textContent LIKE '%?%' ORDER BY createTime ASC

2.5 分页搜索 LIMIT

SELECT * FROM ${tablename} WHERE chatId=? ORDER BY createTime ASC LIMIT ${page * limit}, ${limit}

2.6 查找唯一不同值 DISTINCT

SELECT DISTINCT chatId FROM ${tablename}

2.7 查找个数 COUNT(*)

SELECT COUNT(*) FROM ${tablename} WHERE chatId=?

2.8 条件查询 >,<,>=,<=

3.更新UPDATE

UPDATE ${tablename} SET status=? WHERE chatMsgId=?

4.删除delete

DELETE FROM ${tablename} WHERE chatId=?

上一篇 下一篇

猜你喜欢

热点阅读