Mysql实用示例

Mysql实用示例:

返回id集合的字符串,用逗号隔开:id1,id2,id3,...,idn

1
SELECT GROUP_CONCAT(id) FROM t1

注意:长度超过1024时,会被截断

查询某个字段出现N次的数据

1
2
3
4
5
SELECT
uid,COUNT(uid) AS num
FROM gzszf_meeting_notice_org_staff
WHERE meetingId='318' AND isDelet=0
GROUP BY uid HAVING num>N

批量插入

  1. 数据量大的时候,先忽略掉索引,结束后再恢复,可以提高速度
    1
    2
    SHOW VARIABLES LIKE 'log_bin_trust_function_creators';
    SET GLOBAL log_bin_trust_function_creators=1;