您的位置:首页 > 数据库 > MySQL

mysql视图创0建,分组查询第一条记录

2016-12-15 18:19 274 查看
需求: 查询首次充值成功的记录

-- 查询语句创建首充视图

CREATE VIEW tbl_first_charge_money_view as

SELECT user_id,Min(creat_time) creat_time from tbl_charge_money where state=200 GROUP BY user_id;

CREATE VIEW first_charge_detail_view as

SELECT u.id shower_id ,u.nick_name,a.* from tbl_charge_money a LEFT JOIN tbl_first_charge_money_view b

on a.user_id = b.user_id

LEFT JOIN tbl_room r on a.room_id = r.id LEFT JOIN tbl_user u on u.id = r.shower_id

where a.creat_time = b.creat_time and a.room_id is not null ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql