56,803
社区成员




CREATE TABLE `points` (s
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`activity_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '项目',
`customer_id` int(10) NOT NULL DEFAULT 0 COMMENT '用户',
`point` int(10) NOT NULL DEFAULT 0 COMMENT '积分值',
`ranking` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '当前排行',
`create_time` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '最后更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uni_activity_user` (`activity_id`,`customer_id`) USING BTREE,
KEY `idx_activity` (`activity_id`,`point`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='积分';
UPDATE points AS p,
(SELECT @a:=@a+1 AS ranks, a.id as ids FROM points AS a,(SELECT @a:=0) r
WHERE a.activity_id = 7241 AND a.point > 0 ORDER BY a.point DESC, a.id ASC) AS b
SET p.ranking = ranks WHERE p.id = b.ids;
SELECT * FROM points WHERE activity_id = 7241 AND point > 0
ORDER BY point DESC,id;