MySQL query 技巧

為每列資料增加totalCount欄位

SELECT *,(SELECT COUNT(*) FROM mytable) AS totalCount FROM mytable LIMIT 15,2;

ps: subquery比使用SELECT *+SELECT COUNT(*)速度快3倍

查詢包含某欄位的table

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('column1', 'column2')
AND TABLE_SCHEMA='db_name';

results matching ""

    No results matching ""