SELECT id,u_id,tag_id,COUNT(u_id) AS COUNT FROM ykj_tags GROUP BY u_id HAVING COUNT(u_id) >1 ORDER BY COUNT DESC;
查询结果:
SELECT id,u_id,tag_id FROM ykj_tags WHERE u_id IN ( SELECT u_id FROM ykj_tags GROUP BY u_id HAVING COUNT(u_id)>1)
查询结果:
SELECT user_name,COUNT(*) AS COUNT FROM tp_users WHERE `type`=2 GROUP BY user_name HAVING COUNT>1;
//写原生的查询条件where("FROM_UNIXTIME(create_time,'%Y-%m-%d')='{$date}' and user_id=$this->user_id")SELECT a.user_id AS `编号`,a.account AS `用户ID`,a.mobile AS `手机号码`,a.user_name AS `真实姓名`,(SELECT COUNT(*) FROM tp_users b WHERE b.re_id=a.user_id AND b.is_distribut=1 AND b.`type`=2 AND b.vip_time BETWEEN UNIX_TIMESTAMP('2018-05-08 00:00:00') AND UNIX_TIMESTAMP('2018-05-18 00:00:00')) AS `直推总人数` FROM tp_users a WHERE a.`is_distribut`=1 AND a.`type`=2 HAVING `直推总人数`>=2
SELECT b.account,(SELECT COUNT(*) FROM tp_users AS a WHERE a.`re_id` = b.`user_id` AND a.vip_time BETWEEN UNIX_TIMESTAMP('2018-05-08 00:00:00') AND UNIX_TIMESTAMP('2018-05-18 00:00:00')) AS `countss` ,FLOOR((SELECT COUNT(*) FROM tp_users AS a WHERE a.`re_id` = b.`user_id` AND a.vip_time BETWEEN UNIX_TIMESTAMP('2018-05-08 00:00:00') AND UNIX_TIMESTAMP('2018-05-18 00:00:00'))/2) AS `shuliang` FROM tp_users AS b WHERE b.`is_distribut`=1 AND b.`type`=2 HAVING `countss`>=2