Skip to content

Instantly share code, notes, and snippets.

@onlinelei
Created July 28, 2017 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlinelei/7f07d93c18656797f8b9f3c92d37f9b5 to your computer and use it in GitHub Desktop.
Save onlinelei/7f07d93c18656797f8b9f3c92d37f9b5 to your computer and use it in GitHub Desktop.
mysql
-- mysql单条SQL查询出分页和总数
SELECT SQL_CALC_FOUND_ROWS t.* FROM ( SELECT 1 AS allCount,
dr.id AS reportId
FROM dr_daily dr
WHERE 1=1
GROUP BY dr.id
ORDER BY dr.create_time DESC
)t
LIMIT 1,2
UNION ALL SELECT FOUND_ROWS() AS allCount, NULL
-- 假设要按照用户表 user 用户名 Username 的拼音排序
SELECT * FROM user ORDER BY CONVERT(Username USING gbk) COLLATE gbk_chinese_ci DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment