├── 2015年终数据报告 ├── 2015年终数据汇总 ├── README.md ├── 交易次数 ├── 交易渠道分布 ├── 产品数据需求 ├── 合伙人 ├── 周报 ├── 平均花费时长 ├── 当日注册用户中的交易用户数量 ├── 微信端每日交易数据 ├── 拼团 ├── 新老用户交易区分 ├── 日报 ├── 日报-渠道明 ├── 月报 ├── 每日完成情况 ├── 每日用户留存 ├── 每日登录与签到 ├── 每日资金流动 ├── 活跃时间段分布 ├── 渠道交易分布(新版) ├── 渠道转化率 ├── 用户星座 ├── 用户画像 ├── 账户余额 ├── 邀请与渠道 └── 首次交易 /2015年终数据报告: -------------------------------------------------------------------------------- 1 | 【交易数据】 2 | 1、累计交易额 3 | SELECT sum(amount+assetamount+bonusamount+couponamount) 4 | FROM da_account_trade 5 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20; 6 | 7 | 2、每月交易额 8 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+assetamount+bonusamount+couponamount) 9 | FROM da_account_trade 10 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 11 | GROUP BY 1; 12 | 13 | 3、最高单日交易额(前10天) 14 | SELECT date(createtime),sum(amount+assetamount+bonusamount+couponamount) 15 | FROM da_account_trade 16 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 17 | GROUP BY 1 18 | ORDER BY 2 DESC 19 | LIMIT 10; 20 | 交易三次及三次以上的用户数 21 | SELECT accountid,count(accountid) 22 | FROM da_account_trade 23 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 24 | GROUP BY 1 25 | HAVING count(accountid)>2; 26 | 27 | 4、2015年总收益 28 | 点点宝总收益 29 | SELECT sum(income) FROM account_ddb_income 30 | 点点宝收益————最高收益个人排名 31 | SELECT accountid,sum(amount),sum(income) 32 | FROM account_ddb_income 33 | GROUP BY 1 34 | ORDER BY 3 DESC; 35 | 优选理财总收益 36 | SELECT sum(income) FROM account_selfitem_income 37 | 优选理财收益————最高收益个人排名 38 | SELECT accountid,sum(income) 39 | FROM account_selfitem_income 40 | GROUP BY 1 41 | ORDER BY 2 DESC 42 | 总收益计算: 43 | SELECT a.accountid,sum(a+b) 44 | FROM 45 | (SELECT accountid,sum(amount),sum(income) as a FROM account_ddb_income GROUP BY 1) a 46 | LEFT JOIN 47 | (SELECT accountid,sum(income) as b FROM account_selfitem_income GROUP BY 1) b 48 | ON a.accountid=b.accountid 49 | GROUP BY 1 50 | ORDER BY 2 DESC 51 | LIMIT 20; 52 | 53 | 【用户数据】 54 | 1、人均投资额 55 | SELECT count(DISTINCT(accountid)),sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) 56 | FROM da_account_trade 57 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 58 | 2、投资额排行榜 59 | SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) 60 | FROM da_account_trade 61 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 62 | GROUP BY 1 63 | ORDER BY 2 DESC 64 | LIMIT 10; 65 | 3、人均交易次数 66 | SELECT count(accountid)/count(DISTINCT(accountid)) 67 | FROM da_account_trade 68 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20; 69 | 70 | 4、最多交易次数 71 | SELECT accountid,count(accountid) 72 | FROM da_account_trade 73 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 74 | GROUP BY 1 75 | ORDER BY 2 DESC 76 | LIMIT 10; 77 | 78 | 5、年龄交叉交易额 79 | select nnd,count(*),sum(sum) 80 | from 81 | (select case 82 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 83 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 84 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 85 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 86 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 87 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd,sum 88 | FROM 89 | (SELECT id,IDdate FROM da_ds_account_0111) a 90 | JOIN 91 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 92 | FROM da_account_trade 93 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 94 | GROUP BY 1) b 95 | ON a.id=b.accountid )aaa 96 | GROUP BY 1; 97 | 98 | 6、性别交叉交易额 99 | SELECT gender,count(id),sum(sum) 100 | FROM 101 | (SELECT id,gender FROM da_ds_account_0111) a 102 | JOIN 103 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 104 | FROM da_account_trade 105 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 106 | GROUP BY 1) b 107 | ON a.id=b.accountid 108 | GROUP BY 1; 109 | 110 | 7、星座交叉交易额 111 | select nnd,count(*),sum(sum) 112 | from 113 | (select case 114 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 115 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 116 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 117 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 118 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 119 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 120 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 121 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 122 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 123 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 124 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 125 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd,sum 126 | FROM 127 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 128 | FROM da_account_trade where biztype in (1,3) AND inouttype=1 AND `status`=20 GROUP BY 1) a 129 | LEFT JOIN 130 | (SELECT id,iDdate FROM ds_account ) b 131 | on a.accountid=b.id ) x 132 | group by nnd 133 | order by 3 DESC; 134 | 135 | 8、地区交叉交易额 136 | SELECT left(a.mobilelocation,2),count(*),sum(sum) 137 | SELECT mobilelocation,count(*),sum(sum) 138 | -- SELECT * 139 | FROM 140 | (SELECT accountid,mobilelocation 141 | FROM da_ds_account_variable_0111 142 | where mobilelocation is not null) a 143 | RIGHT JOIN 144 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 145 | FROM da_account_trade 146 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 GROUP BY 1) b 147 | ON a.accountid=b.accountid 148 | GROUP BY 1 149 | ORDER BY 3 DESC; 150 | 151 | 【2015年终汇总】 152 | 【汇总】 153 | 1、下载(从什么时间开始) 154 | --截止2016-01-12,友盟统计数据显示,点点搜财下载总量达到:1040223次 155 | 2、注册 156 | SELECT count(id) 157 | FROM da_account 158 | WHERE DATE_FORMAT(registtime,'%Y')='2015'; 159 | --每个月的注册量 160 | SELECT DATE_FORMAT(registtime,'%Y-%m'),count(id) 161 | FROM da_account 162 | WHERE DATE_FORMAT(registtime,'%Y')='2015' 163 | GROUP BY 1; 164 | 3、绑卡 165 | SELECT count(id) 166 | FROM ds_account 167 | WHERE DATE_FORMAT(registtime,'%Y')='2015' AND realname is not null; 168 | --每个月的绑卡量 169 | SELECT DATE_FORMAT(registtime,'%Y-%m'),count(id) 170 | FROM ds_account 171 | WHERE DATE_FORMAT(registtime,'%Y')='2015' AND realname is not null 172 | GROUP BY 1; 173 | 4、交易 174 | SELECT count(accountid),count(DISTINCT(accountid)),sum(amount+assetamount+bonusamount+couponamount) 175 | FROM da_account_trade 176 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015'; 177 | --只交易两次 178 | SELECT count(accountid),sum(sum) 179 | FROM 180 | (SELECT accountid,count(accountid),sum(amount+assetamount+bonusamount+couponamount) as sum 181 | FROM da_account_trade 182 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 183 | GROUP BY 1 184 | HAVING count(accountid)=2) aaa; 185 | --交易三次及三次以上 186 | SELECT count(accountid),sum(count),sum(sum) 187 | FROM 188 | (SELECT accountid,count(accountid) as count,sum(amount+assetamount+bonusamount+couponamount) as sum 189 | FROM da_account_trade 190 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 191 | GROUP BY 1 192 | HAVING count(accountid)>2) aaa; 193 | 5、交易总额 194 | SELECT sum(amount+assetamount+bonusamount+couponamount) as sum 195 | FROM da_account_trade 196 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015'; 197 | --每月交易总额 198 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+assetamount+bonusamount+couponamount) as sum 199 | FROM da_account_trade 200 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 201 | GROUP BY 1; 202 | --日均总额 203 | SELECT avg(sum) 204 | FROM 205 | (SELECT DATE_FORMAT(createtime,'%Y-%m-%d'),sum(amount+assetamount+bonusamount+couponamount) as sum 206 | FROM da_account_trade 207 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 208 | GROUP BY 1) aa; 209 | 6、红包总额 210 | --红包发放总额 211 | SELECT sum(bonus) 212 | FROM account_bonus 213 | WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=1; 214 | --各种红包类型的发放金额分布 215 | SELECT bonustype,sum(bonus) 216 | FROM account_bonus 217 | WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=1 218 | GROUP BY 1; 219 | --红包使用总额 220 | SELECT sum(bonus) 221 | FROM account_bonus 222 | WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2; 223 | --各种红包类型的使用金额分布 224 | SELECT bonustype,sum(bonus) 225 | FROM account_bonus 226 | WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2 227 | GROUP BY 1; 228 | 7、现金券总额 229 | --现金券发放总额 230 | SELECT sum(money) 231 | FROM account_coupons 232 | WHERE DATE_FORMAT(createtime,'%Y')='2015'; 233 | --现金券使用金额 234 | SELECT sum(money) 235 | FROM account_coupons_used 236 | WHERE DATE_FORMAT(createtime,'%Y')='2015'; 237 | --现金券过期总金额 238 | SELECT sum(money) 239 | FROM account_coupons_expire 240 | WHERE DATE_FORMAT(endtime,'%Y')='2015'; 241 | 8、收益总额 242 | --总收益 243 | SELECT a.dda,sum(x+y) 244 | FROM 245 | (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as x FROM account_ddb_income WHERE DATE_FORMAT(incomedate,'%Y')='2015') a 246 | JOIN 247 | (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as y FROM account_selfitem_income WHERE DATE_FORMAT(incomedate,'%Y')='2015') b 248 | ON a.dda=b.dda; 249 | --点点宝总收益(已经发放,不包括已经产生但是还没有发放的部分) 250 | SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as x 251 | FROM account_ddb_income 252 | WHERE DATE_FORMAT(incomedate,'%Y')='2015'; 253 | --优选理财总收益(已经发放的,不包括已经产生但是还没有发放的部分) 254 | SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as y 255 | FROM account_selfitem_income 256 | WHERE DATE_FORMAT(incomedate,'%Y')='2015'; 257 | 【用户-交易】 258 | 1、用户(下载——注册——绑卡——交易) 259 | 2、交易额(总额-人均-笔均-日均-月均)(相当于… …) 260 | --总计交易人数,交易笔数,交易额,人均,笔均 261 | SELECT count(accountid) 笔数, 262 | count(DISTINCT(accountid)) 人数, 263 | sum(amount+assetamount+bonusamount+couponamount) 交易总额, 264 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) 人均, 265 | sum(amount+assetamount+bonusamount+couponamount)/count(accountid) 笔均 266 | FROM da_account_trade 267 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015'; 268 | --月均总额 269 | SELECT avg(sum) 270 | FROM 271 | (SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+assetamount+bonusamount+couponamount) as sum 272 | FROM da_account_trade 273 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 274 | GROUP BY 1) aa; 275 | --日均总额 276 | SELECT avg(sum) 277 | FROM 278 | (SELECT DATE_FORMAT(createtime,'%Y-%m-%d'),sum(amount+assetamount+bonusamount+couponamount) as sum 279 | FROM da_account_trade 280 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 281 | GROUP BY 1) aa; 282 | 3、交易次数 --次交易-交易额-人均交易额 283 | SELECT times,count(times),sum(count),sum(sum),sum(sum)/count(times) 284 | FROM 285 | (SELECT case 286 | WHEN count(accountid)=1 THEN '1次' 287 | WHEN count(accountid)=2 THEN '2次' 288 | WHEN count(accountid)>2 THEN '3次及以上' end as times, 289 | count(accountid) as count, 290 | sum(amount+assetamount+bonusamount+couponamount) as sum 291 | FROM da_account_trade 292 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 293 | GROUP BY accountid) aa 294 | GROUP BY 1; 295 | --1、x次交易的用户星座分布 296 | select nnd,count(*),sum(sum),sum(sum)/count(*),count(*)/(sum(sum)/10000) 297 | from 298 | (select case 299 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 300 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 301 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 302 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 303 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 304 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 305 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 306 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 307 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 308 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 309 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 310 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd,sum 311 | FROM 312 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 313 | FROM da_account_trade where biztype in (1,3) AND inouttype=1 AND `status`=20 314 | GROUP BY 1 315 | HAVING count(accountid)=1) a 316 | LEFT JOIN 317 | (SELECT id,iDdate FROM ds_account ) b 318 | on a.accountid=b.id ) x 319 | group by nnd 320 | order by 3 DESC; 321 | 322 | --2、x次交易的用户性别分布 323 | SELECT gender,count(id),sum(sum),sum(sum)/count(id),count(id)/(sum(sum)/10000) 324 | FROM 325 | (SELECT id,gender FROM da_ds_account_0111) a 326 | JOIN 327 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 328 | FROM da_account_trade 329 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 330 | GROUP BY 1 331 | HAVING count(accountid)=1) b 332 | ON a.id=b.accountid 333 | GROUP BY 1; 334 | --3、x次交易的用户省份分布 335 | SELECT left(a.mobilelocation,2),count(*),sum(sum),count(*)/(sum(sum)/10000) 336 | SELECT mobilelocation,count(*),sum(sum) 337 | FROM 338 | (SELECT accountid,mobilelocation 339 | FROM da_ds_account_variable_0111 340 | where mobilelocation is not null) a 341 | RIGHT JOIN 342 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 343 | FROM da_account_trade 344 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 345 | GROUP BY 1 346 | HAVING count(accountid)=2) b 347 | ON a.accountid=b.accountid 348 | GROUP BY 1 349 | ORDER BY 3 DESC 350 | LIMIT 15; 351 | --4、x次交易的用户年龄层分布 352 | select nnd,count(*),sum(sum),sum(sum)/count(*),count(*)/(sum(sum)/10000) 353 | from 354 | (select case 355 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 356 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 357 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 358 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 359 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 360 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd,sum 361 | FROM 362 | (SELECT id,IDdate FROM da_ds_account_0111) a 363 | JOIN 364 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 365 | FROM da_account_trade 366 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 367 | GROUP BY 1 368 | HAVING count(accountid)=1) b 369 | ON a.id=b.accountid )aaa 370 | GROUP BY 1; 371 | --5、上面三种类型人数百分比-交易额百分比 372 | (基于最开始的基础数据换算) 373 | 4、年龄层(各年龄层交易人数-交易额-平均交易额-平均交易次数-每万元交易人数) 374 | select nnd,count(*),sum(sum),sum(sum)/count(*),count(*)/(sum(sum)/10000) 375 | from 376 | (select case 377 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 378 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 379 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 380 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 381 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 382 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd,sum 383 | FROM 384 | (SELECT id,IDdate FROM da_ds_account_0111) a 385 | JOIN 386 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 387 | FROM da_account_trade 388 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 389 | GROUP BY 1) b 390 | ON a.id=b.accountid )aaa 391 | GROUP BY 1; 392 | 5、性别(个性别交易人数-交易总额-平均交易额-平均交易次数-每万元交易人数) 393 | SELECT gender,count(id),sum(sum),sum(sum)/count(id),count(id)/(sum(sum)/10000) 394 | FROM 395 | (SELECT id,gender FROM da_ds_account_0111) a 396 | JOIN 397 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 398 | FROM da_account_trade 399 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 400 | GROUP BY 1) b 401 | ON a.id=b.accountid 402 | GROUP BY 1; 403 | 6、地区(各地区交易人数-交易总额-平均交易额-平均交易次数-每万元交易人数) 404 | SELECT left(a.mobilelocation,2),count(*),sum(sum),count(*)/(sum(sum)/10000) 405 | SELECT mobilelocation,count(*),sum(sum) 406 | FROM 407 | (SELECT accountid,mobilelocation 408 | FROM da_ds_account_variable_0111 409 | where mobilelocation is not null) a 410 | RIGHT JOIN 411 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 412 | FROM da_account_trade 413 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 414 | GROUP BY 1 ) b 415 | ON a.accountid=b.accountid 416 | GROUP BY 1 417 | ORDER BY 3 DESC 418 | LIMIT 15; 419 | 7、星座(各星座交易人数-交易总额-平均交易额-平均交易次数-每万元交易人数) 420 | select nnd,count(*),sum(sum),sum(sum)/count(*),count(*)/(sum(sum)/10000) 421 | from 422 | (select case 423 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 424 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 425 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 426 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 427 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 428 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 429 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 430 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 431 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 432 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 433 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 434 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd,sum 435 | FROM 436 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 437 | FROM da_account_trade 438 | where biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 439 | GROUP BY 1) a 440 | LEFT JOIN 441 | (SELECT id,iDdate FROM ds_account ) b 442 | on a.accountid=b.id ) x 443 | group by nnd 444 | order by 3 DESC; 445 | 8、交易活跃时间段分布(24小时制) 446 | SELECT hour(createtime),count(*) 447 | FROM da_account_trade 448 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 449 | GROUP BY 1; 450 | 【行为数据】 451 | 1、访问量(从什么时候开始) 452 | 2、每天访问次数 453 | 3、最常访问的功能 454 | 4、手机型号分布 455 | 5、访问深度 456 | 6、访问时长 457 | 7、转化率 458 | 8、开机次数(日均-人均) 459 | 9、访问活跃时间段分布 460 | 【产品】 461 | 1、产品总数:点点宝--优选理财—新手标 462 | SELECT tag,count(*) 463 | FROM selfitem 464 | WHERE DATE_FORMAT(starttime,'%Y')='2015' 465 | GROUP BY 1; 466 | --已经售完产品数量 467 | SELECT count(id) 468 | FROM selfitem 469 | WHERE DATE_FORMAT(starttime,'%Y')='2015' AND `status`!=1 470 | --已经销售完的每个产品的平均销售时长(小时) 471 | SELECT avg(ttt) 472 | FROM 473 | (SELECT id,TIMESTAMPDIFF(hour,starttime,endtime) as ttt 474 | FROM selfitem 475 | WHERE DATE_FORMAT(starttime,'%Y')='2015' AND `status`!=1 476 | GROUP BY 1) a; 477 | 2、各类产品分布:数量-交易额-交易人数-人均交易额-每万元交易人数-各产品实际销售时间 478 | --各类产品数量-交易人数-人均交易额-笔均交易额-每万元交易人数 479 | SELECT left(itemtitle,3),count(DISTINCT(id)),count(accountid), 480 | count(DISTINCT(accountid)) 交易人数, 481 | sum(amount+assetamount+bonusamount+couponamount) 交易总额, 482 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) 人均交易额, 483 | sum(amount+assetamount+bonusamount+couponamount)/count(accountid) 笔均交易额, 484 | count(DISTINCT(accountid))/(sum(amount+assetamount+bonusamount+couponamount)/10000) 每万元交易额 485 | FROM 486 | (SELECT id,itemtitle 487 | FROM selfitem 488 | WHERE DATE_FORMAT(starttime,'%Y')='2015') a 489 | LEFT JOIN 490 | (SELECT accountid,itemid,amount,assetamount,bonusamount,couponamount 491 | FROM da_account_trade 492 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' ) b 493 | ON a.id=b.itemid 494 | GROUP BY 1; 495 | --各类产品实际销售时间(最容易卖掉的产品类型) 496 | SELECT left(itemtitle,3),avg(ttt) 497 | FROM 498 | (SELECT id,itemtitle,TIMESTAMPDIFF(hour,starttime,endtime) as ttt 499 | FROM selfitem 500 | WHERE DATE_FORMAT(starttime,'%Y')='2015' AND `status`!=1 501 | GROUP BY 1) a 502 | GROUP BY 1 503 | ORDER BY 2; 504 | 3、产品--周期分布:数量-交易额-交易人数-人均交易额-每万元交易人数(比例) 505 | SELECT totalperiods,count(DISTINCT(id)),count(accountid), 506 | count(DISTINCT(accountid)) 交易人数, 507 | sum(amount+assetamount+bonusamount+couponamount) 交易总额, 508 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) 人均交易额, 509 | sum(amount+assetamount+bonusamount+couponamount)/count(accountid) 笔均交易额, 510 | count(DISTINCT(accountid))/(sum(amount+assetamount+bonusamount+couponamount)/10000) 每万元交易额 511 | FROM 512 | (SELECT id,totalperiods 513 | FROM selfitem 514 | WHERE DATE_FORMAT(starttime,'%Y')='2015') a 515 | LEFT JOIN 516 | (SELECT accountid,itemid,amount,assetamount,bonusamount,couponamount 517 | FROM da_account_trade 518 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' ) b 519 | ON a.id=b.itemid 520 | GROUP BY 1; 521 | --各周期产品销售时长分布(各个周期的产品最容易销售排行榜) 522 | SELECT totalperiods,avg(ttt) 523 | FROM 524 | (SELECT id,totalperiods,TIMESTAMPDIFF(hour,starttime,endtime) as ttt 525 | FROM selfitem 526 | WHERE DATE_FORMAT(starttime,'%Y')='2015' AND `status`!=1 527 | GROUP BY 1) a 528 | GROUP BY 1 529 | ORDER BY 2; 530 | 4、产品--利率分布:数量-交易额-交易人数-人均交易额-每万元交易人数(比例) 531 | SELECT annualrate,count(DISTINCT(id)),count(accountid), 532 | count(DISTINCT(accountid)) 交易人数, 533 | sum(amount+assetamount+bonusamount+couponamount) 交易总额, 534 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) 人均交易额, 535 | sum(amount+assetamount+bonusamount+couponamount)/count(accountid) 笔均交易额, 536 | count(DISTINCT(accountid))/(sum(amount+assetamount+bonusamount+couponamount)/10000) 每万元交易额 537 | FROM 538 | (SELECT id,annualrate 539 | FROM selfitem 540 | WHERE DATE_FORMAT(starttime,'%Y')='2015') a 541 | LEFT JOIN 542 | (SELECT accountid,itemid,amount,assetamount,bonusamount,couponamount 543 | FROM da_account_trade 544 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' ) b 545 | ON a.id=b.itemid 546 | GROUP BY 1; 547 | --各利率产品销售时长分布(各个周期的产品最容易销售排行榜) 548 | SELECT annualrate,avg(ttt) 549 | FROM 550 | (SELECT id,annualrate,TIMESTAMPDIFF(hour,starttime,endtime) as ttt 551 | FROM selfitem 552 | WHERE DATE_FORMAT(starttime,'%Y')='2015' AND `status`!=1 553 | GROUP BY 1) a 554 | GROUP BY 1 555 | ORDER BY 2; 556 | 5、发布时间分布: 557 | --产品发布时间时段分布(月份) 558 | SELECT DATE_FORMAT(starttime,'%Y-%m'),count(*) 559 | FROM selfitem 560 | WHERE DATE_FORMAT(starttime,'%Y')='2015' 561 | GROUP BY 1; 562 | --产品发布时间时段分布(小时) 563 | SELECT hour(starttime),count(*) 564 | -- SELECT starttime 565 | FROM selfitem 566 | WHERE DATE_FORMAT(starttime,'%Y')='2015' 567 | GROUP BY 1; 568 | 6、募款类型(selfitem表中的status字段) 569 | SELECT `status`,count(*) 570 | FROM selfitem 571 | WHERE DATE_FORMAT(starttime,'%Y')='2015' 572 | GROUP BY 1; 573 | 7、最喜欢点点宝的星座,性别,年龄层,城市分布 574 | --最喜欢点点宝产品的星座分布 575 | select nnd,count(*),sum(sum),sum(sum)/count(*),count(*)/(sum(sum)/10000) 576 | from 577 | (select case 578 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 579 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 580 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 581 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 582 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 583 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 584 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 585 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 586 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 587 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 588 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 589 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd,sum 590 | FROM 591 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 592 | FROM da_account_trade 593 | where biztype=1 AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 594 | GROUP BY 1) a 595 | LEFT JOIN 596 | (SELECT id,iDdate FROM ds_account ) b 597 | on a.accountid=b.id ) x 598 | group by nnd 599 | order by 2 DESC; 600 | --最喜欢点点宝产品的性别分布 601 | SELECT gender,count(id),sum(sum),sum(sum)/count(id),count(id)/(sum(sum)/10000) 602 | FROM 603 | (SELECT id,gender FROM da_ds_account_0111) a 604 | JOIN 605 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 606 | FROM da_account_trade 607 | WHERE biztype=1 AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 608 | GROUP BY 1) b 609 | ON a.id=b.accountid 610 | GROUP BY 1; 611 | --最喜欢点点宝产品的年龄层分布 612 | select nnd,count(*),sum(sum),sum(sum)/count(*),count(*)/(sum(sum)/10000) 613 | from 614 | (select case 615 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 616 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 617 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 618 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 619 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 620 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd,sum 621 | FROM 622 | (SELECT id,IDdate FROM da_ds_account_0111) a 623 | JOIN 624 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 625 | FROM da_account_trade 626 | WHERE biztype=1 AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 627 | GROUP BY 1) b 628 | ON a.id=b.accountid )aaa 629 | GROUP BY 1; 630 | --最喜欢点点宝产品的城市分布 631 | SELECT left(a.mobilelocation,2),count(*),sum(sum),count(*)/(sum(sum)/10000) 632 | SELECT mobilelocation,count(*),sum(sum) 633 | FROM 634 | (SELECT accountid,mobilelocation 635 | FROM da_ds_account_variable_0111 636 | where mobilelocation is not null) a 637 | RIGHT JOIN 638 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 639 | FROM da_account_trade 640 | WHERE biztype=1 AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 641 | GROUP BY 1 ) b 642 | ON a.accountid=b.accountid 643 | GROUP BY 1 644 | ORDER BY 3 DESC; 645 | 【渠道】 646 | 1、渠道总数(总数) 647 | SELECT channel,count(id),count(realname), 648 | count(accountid),sum(sum), 649 | sum(sum)/count(accountid) 人均交易额, 650 | count(accountid)/(sum(sum)/10000) 每万元交易用户数 651 | FROM 652 | (SELECT id,realname,channel FROM ds_account WHERE DATE_FORMAT(registtime,'%Y')='2015') a 653 | LEFT JOIN 654 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 655 | FROM da_account_trade 656 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 657 | GROUP BY 1) b 658 | ON a.id =b.accountid 659 | GROUP BY 1 660 | ORDER BY 5 DESC; 661 | 2、自然渠道(总数-各注册-绑卡-交易-交易额-人均交易额-每万元交易人数) 662 | SELECT channel,count(id),count(realname), 663 | count(accountid),sum(sum), 664 | sum(sum)/count(accountid) 人均交易额, 665 | count(accountid)/(sum(sum)/10000) 每万元交易用户数 666 | FROM 667 | (SELECT id,realname,channel FROM ds_account WHERE DATE_FORMAT(registtime,'%Y')='2015' 668 | AND channel not in ('360yuansheng','8868','feipao','feipao2','feipao3','feipao4','dandanzuan','xiaoniao', 669 | '360','baiducpd','jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4','xiaomi','lianxiang', 670 | 'kumi','dianju')) a 671 | LEFT JOIN 672 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 673 | FROM da_account_trade 674 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 675 | GROUP BY 1) b 676 | ON a.id =b.accountid 677 | GROUP BY 1 678 | ORDER BY 5 DESC; 679 | 3、付费渠道(总数-注册-绑卡-交易-交易额-人均交易额-花费-平均花费-每万元交易人数) 680 | SELECT channel,count(id),count(realname), 681 | count(accountid),sum(sum), 682 | sum(sum)/count(accountid) 人均交易额, 683 | count(accountid)/(sum(sum)/10000) 每万元交易用户数 684 | FROM 685 | (SELECT id,realname,channel FROM ds_account WHERE DATE_FORMAT(registtime,'%Y')='2015' 686 | AND channel in ('360yuansheng','8868','feipao','feipao2','feipao3','feipao4','dandanzuan','xiaoniao', 687 | '360','baiducpd','jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4','xiaomi','lianxiang', 688 | 'kumi','dianju')) a 689 | LEFT JOIN 690 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 691 | FROM da_account_trade 692 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 693 | GROUP BY 1) b 694 | ON a.id =b.accountid 695 | GROUP BY 1 696 | ORDER BY 5 DESC; 697 | 4、微信渠道 698 | SELECT channel,count(id),count(realname), 699 | count(accountid),sum(sum), 700 | sum(sum)/count(accountid) 人均交易额, 701 | count(accountid)/(sum(sum)/10000) 每万元交易用户数 702 | FROM 703 | (SELECT id,realname,channel FROM ds_account WHERE DATE_FORMAT(registtime,'%Y')='2015' AND channel in ('weixin','micromessage')) a 704 | LEFT JOIN 705 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 706 | FROM da_account_trade 707 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 708 | GROUP BY 1) b 709 | ON a.id =b.accountid 710 | GROUP BY 1 711 | ORDER BY 5 DESC; 712 | 【活动】 713 | 1、活动总数 714 | 2、活动涉及总交易额 715 | 3、活动涉及总交易人数 716 | 4、活动覆盖产品数 717 | 5、最成功的活动 718 | 【奖励】 719 | 1、红包发放:个数-人数-金额 720 | SELECT count(id),count(DISTINCT(accountid)),sum(bonus),sum(bonus)/count(id),sum(bonus)/count(DISTINCT(accountid)) 721 | FROM account_bonus 722 | WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=1; 723 | 2、红包使用:个数-人数-金额-使用周期 724 | SELECT count(id),count(DISTINCT(accountid)),sum(bonus),sum(bonus)/count(id),sum(bonus)/count(DISTINCT(accountid)) 725 | FROM account_bonus 726 | WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2; 727 | --红包的平均使用间隔时长 728 | SELECT avg(times) as 天数 729 | FROM 730 | (SELECT a.accountid,timestampdiff(hour,tt2,tt1)/24 as times 731 | FROM 732 | (SELECT accountid,createtime as tt1 FROM account_bonus WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2) a 733 | LEFT JOIN 734 | (SELECT accountid,createtime as tt2 FROM account_bonus WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=1) b 735 | ON a.accountid=b.accountid 736 | GROUP BY 1) aa; 737 | 3、每一块钱的红包能引入的投资金额(使用一块钱红包同时会投资多少钱的理财产品) 738 | SELECT sum(bonusamount),sum(amount+assetamount+bonusamount+couponamount),sum(amount+assetamount+bonusamount+couponamount)/sum(bonusamount) 739 | FROM 740 | (SELECT accountid,amount,assetamount,bonusamount,couponamount 741 | FROM da_account_trade 742 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' AND bonusamount != 0) a; 743 | 4、最喜欢使用红包的星座,城市,性别,年龄 744 | --最喜欢使用红包用户的星座分布 745 | select nnd,count(*) 746 | from 747 | (select case 748 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 749 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 750 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 751 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 752 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 753 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 754 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 755 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 756 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 757 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 758 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 759 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd 760 | FROM 761 | (SELECT accountid FROM account_bonus WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2) a 762 | LEFT JOIN 763 | (SELECT id,iDdate FROM ds_account ) b 764 | on a.accountid=b.id ) x 765 | group by nnd 766 | order by 2 DESC; 767 | --最喜欢使用红包的用户的性别分布 768 | SELECT gender,count(id) 769 | FROM 770 | (SELECT id,gender FROM da_ds_account_0111) a 771 | JOIN 772 | (SELECT accountid FROM account_bonus WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2) b 773 | ON a.id=b.accountid 774 | GROUP BY 1; 775 | --最喜欢使用红包的用户的年龄层分布 776 | select nnd,count(*) 777 | from 778 | (select case 779 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 780 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 781 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 782 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 783 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 784 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd 785 | FROM 786 | (SELECT id,IDdate FROM da_ds_account_0111) a 787 | JOIN 788 | (SELECT accountid FROM account_bonus WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2) b 789 | ON a.id=b.accountid )aaa 790 | GROUP BY 1; 791 | --最喜欢使用红包用户的城市分布 792 | SELECT left(a.mobilelocation,2),count(*) 793 | SELECT mobilelocation,count(*) 794 | FROM 795 | (SELECT accountid,mobilelocation 796 | FROM da_ds_account_variable_0111 797 | where mobilelocation is not null) a 798 | RIGHT JOIN 799 | (SELECT accountid FROM account_bonus WHERE DATE_FORMAT(createtime,'%Y')='2015' AND inouttype=2) b 800 | ON a.accountid=b.accountid 801 | GROUP BY 1 802 | ORDER BY 2 DESC; 803 | 现金券 804 | 1、现金券发放 805 | SELECT count(id),count(DISTINCT(accountid)),sum(money),sum(money)/count(id),sum(money)/count(DISTINCT(accountid)) 806 | FROM account_coupons 807 | WHERE DATE_FORMAT(createtime,'%Y')='2015'; 808 | 2、现金券使用:个数-人数-金额-使用周期 809 | SELECT count(id),count(DISTINCT(accountid)),sum(money),sum(money)/count(id),sum(money)/count(DISTINCT(accountid)) 810 | FROM account_coupons_used 811 | WHERE DATE_FORMAT(createtime,'%Y')='2015'; 812 | --现金券使用者使用间隔时长: 813 | SELECT avg(x) 814 | FROM 815 | (SELECT a.accountid,timestampdiff(hour,tt2,tt1) as x 816 | FROM 817 | (SELECT accountid,createtime as tt1 FROM account_coupons_used WHERE DATE_FORMAT(createtime,'%Y')='2015' AND money>0 GROUP BY 1) a 818 | LEFT JOIN 819 | (SELECT accountid,createtime as tt2 FROM account_coupons WHERE DATE_FORMAT(createtime,'%Y')='2015') b 820 | ON a.accountid=b.accountid 821 | GROUP BY 1 822 | ORDER BY 2 DESC) aa; 823 | 824 | 3、现金券过期 825 | SELECT count(id),count(DISTINCT(accountid)),sum(money),sum(money)/count(id),sum(money)/count(DISTINCT(accountid)) 826 | FROM account_coupons_expire 827 | WHERE DATE_FORMAT(createtime,'%Y')='2015'; 828 | 4、每一块现金券带动的投资额 829 | SELECT count(accountid),sum(couponamount),sum(amount+assetamount+bonusamount+couponamount),sum(amount+assetamount+bonusamount+couponamount)/sum(couponamount) 830 | FROM 831 | (SELECT accountid,amount,assetamount,bonusamount,couponamount 832 | FROM da_account_trade 833 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' AND couponamount>0 834 | GROUP BY 1) aa; 835 | 5、现金券有效期分布 836 | SELECT kk,count(id) 837 | FROM 838 | (SELECT id,TIMESTAMPDIFF(day,starttime,endtime)+1 as kk 839 | FROM account_coupons 840 | WHERE DATE_FORMAT(createtime,'%Y')='2015' 841 | GROUP BY 1) a 842 | GROUP BY 1 843 | ORDER BY 2 DESC; 844 | 6、最常用的现金券面额,周期 845 | --最常使用的现金券的面额分布 846 | SELECT money,count(id) 847 | FROM account_coupons_used 848 | WHERE DATE_FORMAT(createtime,'%Y')='2015' 849 | GROUP BY 1 850 | ORDER BY 2 DESC; 851 | --最常使用的现金券的周期分布 852 | SELECT kk,count(id) 853 | FROM (SELECT id,TIMESTAMPDIFF(day,starttime,endtime)+1 as kk FROM account_coupons_used WHERE DATE_FORMAT(createtime,'%Y')='2015' GROUP BY 1) a 854 | GROUP BY 1 855 | ORDER BY 2 DESC; 856 | 7、最喜欢使用现金券的星座,城市,性别,年龄 857 | --最喜欢使用现金券用户的星座分布 858 | select nnd,count(*) 859 | from 860 | (select case 861 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 862 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 863 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 864 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 865 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 866 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 867 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 868 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 869 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 870 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 871 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 872 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd 873 | FROM 874 | (SELECT accountid FROM account_coupons_used WHERE DATE_FORMAT(createtime,'%Y')='2015'GROUP BY 1) a 875 | LEFT JOIN 876 | (SELECT id,iDdate FROM ds_account ) b 877 | on a.accountid=b.id ) x 878 | group by nnd 879 | order by 2 DESC; 880 | --最喜欢使用红包的用户的性别分布 881 | SELECT gender,count(id) 882 | FROM 883 | (SELECT id,gender FROM da_ds_account_0111) a 884 | JOIN 885 | (SELECT accountid FROM account_coupons_used WHERE DATE_FORMAT(createtime,'%Y')='2015'GROUP BY 1) b 886 | ON a.id=b.accountid 887 | GROUP BY 1; 888 | --最喜欢使用红包的用户的年龄层分布 889 | select nnd,count(*) 890 | from 891 | (select case 892 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 893 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 894 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 895 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 896 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 897 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd 898 | FROM 899 | (SELECT id,IDdate FROM da_ds_account_0111) a 900 | JOIN 901 | (SELECT accountid FROM account_coupons_used WHERE DATE_FORMAT(createtime,'%Y')='2015' GROUP BY 1) b 902 | ON a.id=b.accountid )aaa 903 | GROUP BY 1; 904 | --最喜欢使用红包用户的城市分布 905 | SELECT left(a.mobilelocation,2),count(*) 906 | SELECT mobilelocation,count(*) 907 | FROM 908 | (SELECT accountid,mobilelocation 909 | FROM da_ds_account_variable_0111 910 | where mobilelocation is not null) a 911 | RIGHT JOIN 912 | (SELECT accountid FROM account_coupons_used WHERE DATE_FORMAT(createtime,'%Y')='2015'GROUP BY 1) b 913 | ON a.accountid=b.accountid 914 | GROUP BY 1 915 | ORDER BY 2 DESC; 916 | 加息券 917 | 1、加息券发放 918 | SELECT count(id),count(DISTINCT(accountid)) 919 | SELECT * 920 | FROM account_coupons 921 | WHERE coupontypeid in (100000000000000002,100000000000000003) AND `status`=1 AND DATE_FORMAT(createtime,'%Y')='2015'; 922 | 2、加息券使用 923 | SELECT count(id),count(DISTINCT(accountid)) 924 | FROM account_coupons 925 | WHERE coupontypeid in (100000000000000002,100000000000000003) AND `status`=2 AND DATE_FORMAT(createtime,'%Y')='2015'; 926 | 【邀请】 927 | 1、总的邀请量 928 | SELECT count(commandid),count(DISTINCT(commandid)),count(commandid)/count(DISTINCT(commandid)) 929 | FROM da_account 930 | WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null; 931 | 2、邀请用户:交易人数-交易次数-交易金额-人均交易额-每万元交易用户数(vs渠道用户) 932 | 3、邀请数量:最多邀请量-平均邀请量-最少邀请量 933 | --每个邀请者的邀请用户量 934 | SELECT commandid,count(id) 935 | FROM da_account 936 | WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null 937 | GROUP BY 1 938 | ORDER BY 2 DESC; 939 | 4、邀请用户星座分布(最容易邀请来的用户的星座分布) 940 | select nnd,count(*) 941 | from 942 | (select case 943 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 944 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 945 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 946 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 947 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 948 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 949 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 950 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 951 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 952 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 953 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 954 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd 955 | FROM ds_account 956 | WHERE IDdate is not null AND id in 957 | (SELECT id FROM da_account 958 | WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null)) a 959 | group by nnd 960 | order by 2 DESC; 961 | 5、最容易邀请的性别 962 | SELECT gender,count(*) 963 | FROM 964 | (SELECT id,gender FROM da_ds_account_0111) a 965 | JOIN 966 | (SELECT id 967 | FROM da_account 968 | WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null) b 969 | ON a.id=b.id 970 | GROUP BY 1; 971 | 6、最容易邀请用户的年龄分布 972 | select nnd,count(*) 973 | from 974 | (select case 975 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 976 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 977 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 978 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 979 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 980 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd 981 | from ds_account 982 | WHERE IDdate is not null AND id in (SELECT id FROM da_account WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null)) a 983 | group by nnd 984 | order by 1 DESC; 985 | 7、最容易邀请用户的城市分布 986 | SELECT left(mobilelocation,2)AS 省份,count(accountid) 987 | FROM da_ds_account_variable_1109 988 | where mobilelocation is not null AND accountid in (SELECT id FROM da_account WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null) 989 | GROUP BY 1 990 | ORDER BY 2 DESC; 991 | 8、邀请用户最喜欢的产品分布 992 | --邀请用户最喜欢的产品类型分布 993 | SELECT left(itemtitle,3),count(accountid) 994 | FROM 995 | (SELECT accountid,itemid FROM da_account_trade 996 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y')='2015' 997 | AND accountid in (SELECT id FROM da_account WHERE DATE_FORMAT(registtime,'%Y')='2015' AND commandid is not null)) a 998 | LEFT JOIN 999 | (SELECT id,itemtitle from selfitem) b 1000 | ON itemid= b.id 1001 | GROUP BY 1; 1002 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQL 2 | 日常数据分析SQL语句 3 | -------------------------------------------------------------------------------- /交易次数: -------------------------------------------------------------------------------- 1 | FROM 2 | (SELECT CASE 3 | WHEN count(accountid)=1 THEN '交易1次' 4 | when count(accountid)=2 THEN '交易2次' 5 | when count(accountid)=3 THEN '交易3次' 6 | WHEN count(accountid)>3 THEN '交易3+次' END as times,sum(amount+assetamount+bonusamount+couponamount) as sum 7 | FROM da_account_trade 8 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2015-12-31' 9 | AND accountid in (SELECT accountid FROM da_account_trade 10 | WHERE date(createtime)='2015-12-31' 11 | and `status` =20 and biztype in (1,3) and inouttype = 1) 12 | GROUP BY accountid) aaa 13 | GROUP BY 1; 14 | -------------------------------------------------------------------------------- /交易渠道分布: -------------------------------------------------------------------------------- 1 | select channel,count(distinct(accountid)) 2 | from da_account_trade 3 | group by channel; 4 | -------------------------------------------------------------------------------- /产品数据需求: -------------------------------------------------------------------------------- 1 | -- 2016-12-29 : 用户获取收益: 2 | SELECT accountid,sum(income) 3 | FROM 4 | (SELECT accountid,income FROM account_ddb_income 5 | UNION 6 | SELECT accountid,totalincome as income FROM account_selfitem ) b 7 | GROUP BY 1 8 | HAVING sum(income) > 59.99 ; 9 | 10 | 11 | 12 | -- 2016-12-09 :王昱琛用户风险等级: 13 | SELECT CASE 14 | when riskscore between 0 AND 20 then "0-20" 15 | when riskscore between 21 AND 40 then "21-40" 16 | when riskscore between 41 AND 60 then "41-60" 17 | when riskscore between 61 AND 80 then "61-80" 18 | when riskscore between 81 AND 100 then "81-100" END as rank,count(DISTINCT accountid) 19 | -- SELECT accountid,riskscore 20 | FROM account_business 21 | WHERE riskscore is not null 22 | GROUP BY 1 23 | ORDER BY 2 DESC ; 24 | 25 | 26 | 27 | -- 2016-12-02 :倪妍,最近90天人均交易笔数 28 | SELECT count(*),count(DISTINCT accountid),count(*)/count(DISTINCT accountid) 29 | FROM account_trade 30 | WHERE biztype in (1,3) and inouttype= 1 AND `status`=20 AND date(createtime) BETWEEN '2016-09-02' AND '2016-12-01'; 31 | 32 | -- 2016-08-09:王昱琛:红包存量及其分布: 33 | SELECT sum) 34 | -- SELECT accountid,sum(bonus) 35 | FROM account 36 | GROUP BY 1 37 | 38 | SELECT CASE 39 | WHEN sum BETWEEN 0 AND 50.00 then "0-50" 40 | WHEN sum BETWEEN 50.01 AND 100 then "51-100" 41 | WHEN sum BETWEEN 100.01 AND 500 then "101-500" 42 | WHEN sum BETWEEN 500.01 AND 1000 then "501-1000" 43 | WHEN sum > 1000 then "1000+" END as rank,count(DISTINCT id) 人数,sum(sum) 点币数量,round(sum(sum)/count(id),1) 人均金额 44 | FROM 45 | (SELECT id,sum(bonusasset) as sum FROM account GROUP BY 1 HAVING sum > 0 ) ssss 46 | GROUP BY 1 47 | ORDER BY 2 DESC; 48 | 49 | SELECT count(DISTINCT id),sum(sum) 50 | FROM 51 | ( 52 | SELECT id,sum(bonusasset) as sum 53 | FROM account 54 | WHERE id in (SELECT accountid FROM account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 GROUP BY 1 ) 55 | GROUP BY 1 56 | HAVING sum(bonusasset)>0 57 | ) aaaa; 58 | 59 | -- 2016-08-05 : 60 | SELECT * 61 | FROM score_gain_stream 62 | limit 10 63 | 64 | SELECT score_reason,score_type 65 | FROM score_gain_stream 66 | GROUP BY 1 67 | ORDER BY 2 68 | 69 | SELECT sum(amount),sum(score) 70 | FROM score_gain_stream 71 | -- WHERE score_type=1 72 | -- WHERE score_reason like '%申购%' OR score_reason LIKE '%购买%' 73 | WHERE item_id in (SELECT id FROM selfitem ) 74 | 75 | -- 2016-07-29 :剩余点币分布: 76 | SELECT CASE 77 | WHEN cur_usable_score BETWEEN 0 AND 0 THEN "0个" 78 | WHEN cur_usable_score BETWEEN 1 AND 100 THEN "1-100个" 79 | WHEN cur_usable_score BETWEEN 101 AND 500 THEN "101-500个" 80 | WHEN cur_usable_score BETWEEN 501 AND 1000 THEN "501-1k个" 81 | WHEN cur_usable_score BETWEEN 1001 AND 5000 THEN "1001-5k个" 82 | WHEN cur_usable_score BETWEEN 5001 AND 10000 THEN "5001-1w个" 83 | WHEN cur_usable_score BETWEEN 10001 AND 100000 THEN "10001-10w个" 84 | WHEN cur_usable_score > 100000 THEN "10w+个" END as rank,count(accountid),sum(cur_usable_score),sum(cur_usable_score)/count(accountid) 85 | FROM 86 | (SELECT accountid,cur_usable_score 87 | -- SELECT sum(cur_usable_score) 88 | FROM account_score 89 | GROUP BY 1 90 | HAVING cur_usable_score>0 91 | ) a 92 | GROUP BY 1 93 | ORDER BY 2 DESC; 94 | 95 | SELECT sum(score) 96 | FROM score_cost_stream 97 | LIMIT 10 98 | 99 | SELECT sum(cur_usable_score) as 存量, 100 | sum(total_gain_score) 获取, 101 | sum(total_cost_score) 使用, 102 | sum(total_expire_score) 过期, 103 | sum(total_freeze_score) 冻结 104 | FROM account_score 105 | 106 | -- 2016-07-21 :帮我拉下1000以下,这3个月来的每天平均提现金额 107 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(accountid),count(DISTINCT accountid),sum(sum),sum(sum)/count(DISTINCT date(createtime)) 108 | -- SELECT date(createtime),count(accountid),count(DISTINCT accountid),sum(sum) 109 | FROM 110 | (SELECT accountid,createtime,sum(amount+assetamount+bonusamount+couponamount) as sum 111 | FROM account_trade 112 | WHERE biztype=4 AND inouttype=2 AND `status` in (6,20) 113 | -- AND date(createtime) between '2016-04-20' AND '2016-07-20' 114 | GROUP BY id 115 | HAVING sum<1000 ) a 116 | GROUP BY 1; 117 | 118 | 119 | 120 | 121 | -- 2016-07-07 :强哥,想要用户每月平均提现次数和金额的数据~~~ 122 | -- 提现: 123 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(*),count(DISTINCT accountid),sum(amount+assetamount+bonusamount+couponamount) 124 | FROM account_trade 125 | WHERE biztype=4 AND inouttype=2 AND `status` in (6,20) 126 | GROUP BY 1; 127 | 128 | -- 凯强,又要麻烦你~ 提现金额在2000的 3000的平均每月人数 129 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(accountid),count(DISTINCT accountid),sum(sum) 130 | FROM 131 | (SELECT accountid,createtime,sum(amount+assetamount+bonusamount+couponamount) as sum 132 | FROM account_trade 133 | WHERE biztype=4 AND inouttype=2 AND `status` in (6,20) 134 | GROUP BY id 135 | HAVING sum<2000 ) a 136 | GROUP BY 1; 137 | 138 | 139 | -- 交易: 140 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(*),count(DISTINCT accountid),sum(amount+assetamount+bonusamount+couponamount) 141 | FROM account_trade 142 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 143 | GROUP BY 1; 144 | 145 | 146 | 147 | -- 2017-01-09 :账户余额资金大于0元,小于100元的用户: 148 | SELECT rank,count(DISTINCT accountid),sum(sum)/count(DISTINCT accountid) 149 | FROM 150 | ( 151 | SELECT CASE 152 | WHEN sum(asset) BETWEEN 0.01 AND 10 THEN '一级' 153 | WHEN sum(asset) BETWEEN 10.01 AND 30 THEN '二级' 154 | WHEN sum(asset) BETWEEN 30.01 AND 50 THEN '三级' 155 | WHEN sum(asset) BETWEEN 50.01 AND 80 THEN '四级' 156 | WHEN sum(asset) BETWEEN 80.01 AND 99.99 THEN '五级' end as rank,accountid,sum(asset) as sum 157 | -- SELECT accountid,sum(asset) 158 | FROM ds_save_accountbal_20160706 159 | WHERE saveday='2016-07-05' 160 | GROUP BY accountid 161 | HAVING sum(asset)>0 AND sum(asset)<100 162 | ) aa 163 | GROUP BY 1; 164 | 165 | -- 一个月以内有交易表行为: 166 | -- 一个月以内有访问app行为: 167 | SELECT rank,count(DISTINCT accountid),sum(sum)/count(DISTINCT accountid) 168 | FROM 169 | ( 170 | SELECT CASE 171 | WHEN sum(asset) BETWEEN 0.01 AND 10 THEN '一级' 172 | WHEN sum(asset) BETWEEN 10.01 AND 30 THEN '二级' 173 | WHEN sum(asset) BETWEEN 30.01 AND 50 THEN '三级' 174 | WHEN sum(asset) BETWEEN 50.01 AND 80 THEN '四级' 175 | WHEN sum(asset) BETWEEN 80.01 AND 99.99 THEN '五级' end as rank,accountid,sum(asset) as sum 176 | -- SELECT accountid,sum(asset) 177 | FROM ds_save_accountbal_20160706 178 | WHERE saveday='2016-07-05' 179 | -- AND accountid in (SELECT accountid FROM system_appopenlog where date(opentime) BETWEEN '2016-06-05' AND '2016-07-05' GROUP BY 1 ) #app打开过的用户 180 | -- AND accountid in (SELECT accountid FROM account_trade where biztype in (1,3) AND inouttype=1 AND `status`=20 181 | -- AND date(createtime) BETWEEN '2016-06-05' AND '2016-07-05' GROUP BY 1 HAVING sum(assetamount)>0 ) #交易过的用户 182 | -- AND accountid in (SELECT accountid FROM account_trade where biztype=4 AND inouttype=2 AND `status` in (6,20) 183 | -- AND date(createtime) BETWEEN '2016-06-05' AND '2016-07-05' GROUP BY 1 ) #提现过的用户 184 | AND accountid in (SELECT accountid FROM account_trade GROUP BY 1) #交易表行为的用户 185 | GROUP BY accountid 186 | HAVING sum(asset)>0 AND sum(asset)<100 187 | ) aa 188 | GROUP BY 1; 189 | 190 | 191 | 192 | #账户余额大约0元,并且没有过交易记录的用户: 193 | SELECT accountid,TIMESTAMPDIFF(day,date(now()),date(max(savetime))),sum(asset) 194 | FROM ds_save_accountbal_20160706 195 | WHERE accountid not in (SELECT accountid FROM account_trade GROUP BY 1) 196 | GROUP BY 1 197 | HAVING sum(asset)>0 ; 198 | 199 | 200 | SELECT count(*) 201 | FROM ds_save_accountbal_20160706 202 | WHERE date(saveday)='2016-07-03' 203 | 204 | 205 | -- 2016-05-10 :倪妍:3.0版本用户留存 206 | -- 安卓注册用户: 207 | SELECT id,channel FROM da_account WHERE channel in ('App Store','AppStore') AND date(registtime)>'2016-04-28' 208 | -- 每日注册用户数: 209 | SELECT date(registtime),count(id) 210 | FROM da_account 211 | WHERE channel not in ('App Store','AppStore') AND date(registtime)>'2016-04-27' 212 | GROUP BY 1; 213 | 214 | -- android用户次日留存: 215 | SELECT * 216 | FROM 217 | (SELECT id FROM da_account WHERE channel not in ('App Store','AppStore') AND date(registtime)='2016-05-05' ) a 218 | JOIN 219 | (SELECT accountid FROM system_appopenlog WHERE date(opentime)='2016-05-11' GROUP BY 1 ) b 220 | ON a.id=b.accountid; 221 | 222 | -- IOS用户次日留存: 223 | SELECT * 224 | FROM 225 | (SELECT id FROM da_account WHERE channel in ('AppStore','App Store') AND date(registtime)='2016-04-29' ) a 226 | JOIN 227 | (SELECT accountid FROM system_appopenlog WHERE date(opentime)='2016-05-05' GROUP BY 1 ) b 228 | ON a.id=b.accountid; 229 | 230 | 231 | 232 | 233 | SELECT channel,count(*) 234 | FROM da_account 235 | WHERE channel LIKE '%App%' 236 | GROUP BY 1 237 | ORDER BY 2 DESC 238 | 239 | 240 | -- 2016-05-03 : 241 | -- 激活——注册: 242 | -- 注册——绑卡: 243 | -- 绑卡——交易: 244 | 245 | 246 | 247 | -- 2016-04-25 :产品数据需求:凯强 麻烦你 关于现在在进行的邀请一名好友注册并交易就送20元的这个活动,我想要以下数据:邀请人的人数 、被邀请的人数 、 被邀请人首次投资的额度、 近3个 月。最近三个月邀请人的人数、被邀请的人数 248 | SELECT count(DISTINCT commandid),count(commandid) 249 | -- SELECT * 250 | FROM da_account 251 | WHERE date(registtime)>'2016-01-25' AND commandid is not null 252 | 253 | -- 以上被邀请用户在这段时间的首次交易额 254 | SELECT count(DISTINCT accountid), 255 | sum(amount+assetamount+bonusamount+couponamount), 256 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT accountid) 257 | -- SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) 258 | FROM 259 | (SELECT accountid,itemid,amount,assetamount,bonusamount,couponamount 260 | FROM da_account_trade 261 | WHERE biztype in (1,3) AND inouttype =1 AND `status`=20 262 | AND accountid in (SELECT id FROM da_account WHERE date(registtime)>'2016-01-25' AND commandid is not null ) 263 | GROUP BY 1 ) aaa 264 | GROUP BY 1 265 | ORDER BY 2 DESC 266 | 267 | ================================================================================================================================================================== 268 | ================================================================================================================================================================== 269 | -- 【第一部分:】 270 | -- 1、累计交易额 271 | -- 2、累计交易笔数 272 | SELECT sum(amount+assetamount+bonusamount+couponamount),count(accountid) 273 | FROM account_trade 274 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2017-01-09'; 275 | 276 | -- 3、累计注册用户数 277 | SELECT count(id) FROM account WHERE date(registtime)<'2017-01-09'; 278 | 279 | -- 4、累计投资人赚取收益 280 | -- SELECT a.dda,sum(x+y) 281 | -- FROM 282 | -- (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as x FROM account_ddb_income WHERE date(incomedate)<'2017-01-09') a 283 | -- JOIN 284 | -- (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as y FROM account_selfitem_income WHERE date(incomedate)<'2017-01-09' ) b 285 | -- ON a.dda=b.dda; 286 | 287 | SELECT a.dda,sum(x+y) 288 | FROM 289 | (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as x FROM account_ddb_income WHERE date(incomedate)<'2017-01-09') a 290 | JOIN 291 | (SELECT DATE_FORMAT(createtime,'%Y') as dda,sum(totalincome) as y FROM account_selfitem WHERE date(createtime)<'2017-01-09' ) b 292 | ON a.dda=b.dda; 293 | 294 | -- SELECT DATE_FORMAT(createtime,'%Y') as dda,sum(totalincome) as y FROM account_selfitem WHERE date(createtime)<'2017-01-09' 295 | -- SELECT sum(itemincome) FROM account; 296 | -- 297 | -- 5、兑付率 298 | -- 100% 299 | 300 | -- 【第二部分:】 301 | -- 1、下周兑付项目 302 | -- 2、兑付金额 303 | SELECT count(id),sum(unitprice*totalpcs) 304 | FROM selfitem 305 | WHERE date(nextretdate) BETWEEN '2017-01-09' AND '2017-01-15' 306 | 307 | -- 【第三部分:】投资用户年龄层分布(百分比) 308 | select nnd,count(accountid),sum(sum),sum(sum)/count(accountid) 309 | from 310 | (select case 311 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 312 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 313 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 314 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 315 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 316 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd,accountid,sum 317 | FROM 318 | (SELECT id,IDdate FROM ds_account) a 319 | JOIN 320 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 321 | FROM account_trade 322 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2017-01-09' 323 | GROUP BY 1) b 324 | ON a.id=b.accountid )aaa 325 | GROUP BY 1 326 | ORDER BY 3 DESC; 327 | 328 | -- 【第四部分:】产品期限(周期)占比分布(百分比) 329 | SELECT * FROM selfitem LIMIT 10; 330 | SELECT left(itemtitle,3),count(id) FROM selfitem GROUP BY 1; 331 | 332 | SELECT rank,count(id) 333 | FROM 334 | (-- SELECT totalperiods,count(id),sum(unitprice*totalpcs) 335 | SELECT CASE 336 | WHEN totalperiods BETWEEN 1 AND 15 then '15天' 337 | WHEN totalperiods BETWEEN 16 AND 45 then '30天' 338 | WHEN totalperiods BETWEEN 46 AND 75 then '60天' 339 | WHEN totalperiods BETWEEN 76 AND 135 then '90天' 340 | WHEN totalperiods BETWEEN 136 AND 200 then '180天' 341 | WHEN totalperiods BETWEEN 200 AND 400 then '360天' end as rank,id,totalperiods 342 | FROM selfitem ) aa 343 | GROUP BY 1 344 | ORDER BY 2 DESC; 345 | 346 | -- 【第五部分】产品(利率)占比分布(百分比) 347 | SELECT CASE 348 | WHEN annualrate < 7.6 THEN '7.5%以下' 349 | WHEN annualrate BETWEEN 7.6 AND 8.5 THEN '7.5%-8.5%' 350 | WHEN annualrate BETWEEN 8.6 AND 10.0 THEN '8.6%-10.0%' 351 | WHEN annualrate > 10.0 THEN '10%以上' END as rank,count(id),sum(unitprice*totalpcs) 352 | -- SELECT annualrate,count(id),sum(unitprice*totalpcs) 353 | FROM selfitem 354 | GROUP BY 1 355 | ORDER BY 3 DESC; 356 | 357 | -- 【第六部分】 358 | SELECT CASE 359 | WHEN sum BETWEEN 0 AND 5000 then '0k-5k' 360 | WHEN sum BETWEEN 5001 AND 10000 then '5k-1w' 361 | WHEN sum BETWEEN 10001 AND 50000 then '1w-5w' 362 | WHEN sum BETWEEN 50001 AND 100000 then '5w-10w' 363 | WHEN sum BETWEEN 100001 AND 500000 then '10w-50w' 364 | WHEN sum > 500000 then '50w+' end as rank,count(accountid),sum(sum) 365 | FROM 366 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 367 | FROM account_trade 368 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2017-01-09' 369 | GROUP BY 1 ) aa 370 | GROUP BY 1 371 | ORDER BY 3 DESC; 372 | 373 | -- 2016-05-10 :倪妍:3.0版本用户留存 374 | -- 安卓注册用户: 375 | SELECT id,channel FROM da_account WHERE channel in ('App Store','AppStore') AND date(registtime)>'2016-04-28' 376 | -- 每日注册用户数: 377 | SELECT date(registtime),count(id) 378 | FROM da_account 379 | WHERE channel not in ('App Store','AppStore') AND date(registtime)>'2016-04-27' 380 | GROUP BY 1; 381 | 382 | -- android用户次日留存: 383 | SELECT * 384 | FROM 385 | (SELECT id FROM da_account WHERE channel not in ('App Store','AppStore') AND date(registtime)='2016-05-05' ) a 386 | JOIN 387 | (SELECT accountid FROM system_appopenlog WHERE date(opentime)='2016-05-11' GROUP BY 1 ) b 388 | ON a.id=b.accountid; 389 | 390 | -- IOS用户次日留存: 391 | SELECT * 392 | FROM 393 | (SELECT id FROM da_account WHERE channel in ('AppStore','App Store') AND date(registtime)='2016-04-29' ) a 394 | JOIN 395 | (SELECT accountid FROM system_appopenlog WHERE date(opentime)='2016-05-05' GROUP BY 1 ) b 396 | ON a.id=b.accountid; 397 | 398 | 399 | 400 | 401 | SELECT channel,count(*) 402 | FROM da_account 403 | WHERE channel LIKE '%App%' 404 | GROUP BY 1 405 | ORDER BY 2 DESC 406 | 407 | 408 | -- 2016-05-03 : 409 | -- 激活——注册: 410 | -- 注册——绑卡: 411 | -- 绑卡——交易: 412 | 413 | 414 | 415 | 416 | 417 | -- 2016-04-25 :产品数据需求: 418 | -- 凯强 麻烦你 关于现在在进行的邀请一名好友注册并交易就送20元的这个活动,我想要以下数据:邀请人的人数 、被邀请的人数 、 被邀请人首次投资的额度、 近3个 月。 419 | -- 最近三个月邀请人的人数、被邀请的人数 420 | SELECT count(DISTINCT commandid),count(commandid) 421 | -- SELECT * 422 | FROM da_account 423 | WHERE date(registtime)>'2016-01-25' AND commandid is not null 424 | 425 | -- 以上被邀请用户在这段时间的首次交易额 426 | SELECT count(DISTINCT accountid), 427 | sum(amount+assetamount+bonusamount+couponamount), 428 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT accountid) 429 | -- SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) 430 | FROM 431 | (SELECT accountid,itemid,amount,assetamount,bonusamount,couponamount 432 | FROM da_account_trade 433 | WHERE biztype in (1,3) AND inouttype =1 AND `status`=20 434 | AND accountid in (SELECT id FROM da_account WHERE date(registtime)>'2016-01-25' AND commandid is not null ) 435 | GROUP BY 1 ) aaa 436 | GROUP BY 1 437 | ORDER BY 2 DESC 438 | 439 | 440 | 441 | -- 【第一部分:】 442 | -- 1、累计交易额 443 | -- 2、累计交易笔数 444 | SELECT sum(amount+assetamount+bonusamount+couponamount),count(accountid) 445 | FROM account_trade 446 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-06-27'; 447 | 448 | -- 3、累计注册用户数 449 | SELECT count(id) FROM account WHERE date(registtime)<'2016-06-27'; 450 | 451 | -- 4、累计投资人赚取收益 452 | -- SELECT a.dda,sum(x+y) 453 | -- FROM 454 | -- (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as x FROM account_ddb_income WHERE date(incomedate)<'2016-06-27') a 455 | -- JOIN 456 | -- (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as y FROM account_selfitem_income WHERE date(incomedate)<'2016-06-27' ) b 457 | -- ON a.dda=b.dda; 458 | 459 | SELECT a.dda,sum(x+y) 460 | FROM 461 | (SELECT DATE_FORMAT(incomedate,'%Y') as dda,sum(income) as x FROM account_ddb_income WHERE date(incomedate)<'2016-06-27') a 462 | JOIN 463 | (SELECT DATE_FORMAT(createtime,'%Y') as dda,sum(totalincome) as y FROM account_selfitem WHERE date(createtime)<'2016-06-27' ) b 464 | ON a.dda=b.dda; 465 | 466 | -- SELECT DATE_FORMAT(createtime,'%Y') as dda,sum(totalincome) as y FROM account_selfitem WHERE date(createtime)<'2016-06-27' 467 | -- SELECT sum(itemincome) FROM account; 468 | -- 469 | -- 5、兑付率 470 | -- 100% 471 | 472 | -- 【第二部分:】 473 | -- 1、下周兑付项目 474 | -- 2、兑付金额 475 | SELECT count(id),sum(unitprice*totalpcs) 476 | FROM selfitem 477 | WHERE date(nextretdate) BETWEEN '2016-06-27' AND '2016-07-03' 478 | 479 | 480 | 481 | -- 【第三部分:】投资用户年龄层分布(百分比) 482 | select nnd,count(accountid),sum(sum),sum(sum)/count(accountid) 483 | from 484 | (select case 485 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "2000" AND '2015' then '00后' 486 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1990" AND '1999' then '90后' 487 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1980" AND '1989' then '80后' 488 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1970" AND '1979' then '70后' 489 | when DATE_FORMAT(iDdate,'%Y') BETWEEN "1960" AND '1969' then '60后' 490 | when DATE_FORMAT(iDdate,'%Y') <'1960' then '60前' end as nnd,accountid,sum 491 | FROM 492 | (SELECT id,IDdate FROM ds_account) a 493 | JOIN 494 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 495 | FROM account_trade 496 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-06-27' 497 | GROUP BY 1) b 498 | ON a.id=b.accountid )aaa 499 | GROUP BY 1 500 | ORDER BY 3 DESC; 501 | 502 | -- 【第四部分:】产品期限(周期)占比分布(百分比) 503 | SELECT * FROM selfitem LIMIT 10; 504 | 505 | SELECT left(itemtitle,3),count(id) 506 | FROM selfitem 507 | GROUP BY 1; 508 | 509 | 510 | SELECT rank,count(id) 511 | FROM 512 | (-- SELECT totalperiods,count(id),sum(unitprice*totalpcs) 513 | SELECT CASE 514 | WHEN totalperiods BETWEEN 1 AND 15 then '15天' 515 | WHEN totalperiods BETWEEN 16 AND 45 then '30天' 516 | WHEN totalperiods BETWEEN 46 AND 75 then '60天' 517 | WHEN totalperiods BETWEEN 76 AND 135 then '90天' 518 | WHEN totalperiods BETWEEN 136 AND 200 then '180天' 519 | WHEN totalperiods BETWEEN 200 AND 400 then '360天' end as rank,id,totalperiods 520 | FROM selfitem ) aa 521 | GROUP BY 1 522 | ORDER BY 2 DESC; 523 | 524 | -- 【第五部分】产品(利率)占比分布(百分比) 525 | SELECT CASE 526 | WHEN annualrate < 7.6 THEN '7.5%以下' 527 | WHEN annualrate BETWEEN 7.6 AND 8.5 THEN '7.5%-8.5%' 528 | WHEN annualrate BETWEEN 8.6 AND 10.0 THEN '8.6%-10.0%' 529 | WHEN annualrate > 10.0 THEN '10%以上' END as rank,count(id),sum(unitprice*totalpcs) 530 | -- SELECT annualrate,count(id),sum(unitprice*totalpcs) 531 | FROM selfitem 532 | GROUP BY 1 533 | ORDER BY 3 DESC; 534 | 535 | -- 【第六部分】 536 | SELECT CASE 537 | WHEN sum BETWEEN 0 AND 5000 then '0k-5k' 538 | WHEN sum BETWEEN 5001 AND 10000 then '5k-1w' 539 | WHEN sum BETWEEN 10001 AND 50000 then '1w-5w' 540 | WHEN sum BETWEEN 50001 AND 100000 then '5w-10w' 541 | WHEN sum BETWEEN 100001 AND 500000 then '10w-50w' 542 | WHEN sum > 500000 then '50w+' end as rank,count(accountid),sum(sum) 543 | FROM 544 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 545 | FROM account_trade 546 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-06-27' 547 | GROUP BY 1 ) aa 548 | GROUP BY 1 549 | ORDER BY 3 DESC; 550 | -------------------------------------------------------------------------------- /合伙人: -------------------------------------------------------------------------------- 1 | -- 2017-06-22: 2 | -- 点点合伙人数据需求:(2016年9月份-2017年5月份) 3 | -- 领取到点点佣金的用户名单、每月获得奖励金额、符合档次(5%或者15%)、邀请用户每月投资金额、邀请用户每月持有资产金额、每月有效下线人数 4 | 5 | 6 | SELECT * 7 | FROM 8 | (-- 领取点点二重礼的用户及每月奖励金额: 9 | SELECT accountid 10 | FROM 11 | (SELECT id,accountid FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') 12 | UNION 13 | SELECT id,accountid FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') 14 | ) aa 15 | GROUP BY 1 16 | ) xxxx 17 | LEFT JOIN 18 | 19 | (-- 2016-09月份数据: 20 | SELECT a.accountid as accountid,sums,percent,summ,counts 21 | FROM 22 | (-- 领取点点二重礼的用户及每月奖励金额: 23 | SELECT accountid,sum(money) as sums 24 | FROM 25 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2016-10-01' 26 | UNION 27 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2016-10-01' 28 | ) aa 29 | GROUP BY 1 30 | ) a 31 | LEFT JOIN 32 | (-- 符合等级: 33 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2016-10-01' ) b 34 | ON a.accountid = b.accountid 35 | LEFT JOIN 36 | (-- 邀请好友每月投资金额,有效下线人数: 37 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 38 | FROM account_partner_trade 39 | WHERE date(tradetime) BETWEEN '2016-09-01' AND '2016-09-30' AND tradeid in (SELECT tradeid FROM account_partner_trade WHERE amount>5000 ) 40 | GROUP BY 1 ) c 41 | ON a.accountid = c.partnerid ) aaa 42 | ON xxxx.accountid = aaa.accountid 43 | 44 | LEFT JOIN 45 | (-- 2016-10月份数据: 46 | SELECT a.accountid as accountid,sums,percent,summ,counts 47 | FROM 48 | (-- 领取点点二重礼的用户及每月奖励金额: 49 | SELECT accountid,sum(money) as sums 50 | FROM 51 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2016-11-01' 52 | UNION 53 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2016-11-01' 54 | ) aa 55 | GROUP BY 1 56 | ) a 57 | LEFT JOIN 58 | (-- 符合等级: 59 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2016-11-01' ) b 60 | ON a.accountid = b.accountid 61 | LEFT JOIN 62 | (-- 邀请好友每月投资金额,有效下线人数: 63 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 64 | FROM account_partner_trade WHERE date(tradetime) BETWEEN '2016-10-01' AND '2016-10-31' 65 | AND tradeid in (SELECT tradeid FROM account_partner_trade WHERE amount>5000 ) 66 | GROUP BY 1 ) c 67 | ON a.accountid = c.partnerid ) bbb 68 | ON xxxx.accountid = bbb.accountid 69 | 70 | LEFT JOIN 71 | (-- 2016-11月份数据: 72 | SELECT a.accountid as accountid,sums,percent,summ,counts 73 | FROM 74 | (-- 领取点点二重礼的用户及每月奖励金额: 75 | SELECT accountid,sum(money) as sums 76 | FROM 77 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2016-12-01' 78 | UNION 79 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2016-13-01' 80 | ) aa 81 | GROUP BY 1 82 | ) a 83 | LEFT JOIN 84 | (-- 符合等级: 85 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2016-12-01' ) b 86 | ON a.accountid = b.accountid 87 | LEFT JOIN 88 | (-- 邀请好友每月投资金额,有效下线人数: 89 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 90 | FROM account_partner_trade 91 | WHERE date(tradetime) BETWEEN '2016-11-01' AND '2016-11-31' AND id in (SELECT id FROM account_partner_trade WHERE amount>5000 ) 92 | GROUP BY 1 ) c 93 | ON a.accountid = c.partnerid ) ccc 94 | ON xxxx.accountid = ccc.accountid 95 | LEFT JOIN 96 | (-- 2016-12月份数据: 97 | SELECT a.accountid as accountid,sums,percent,summ,counts 98 | FROM 99 | (-- 领取点点二重礼的用户及每月奖励金额: 100 | SELECT accountid,sum(money) as sums 101 | FROM 102 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-01-01' 103 | UNION 104 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-01-01' 105 | ) aa 106 | GROUP BY 1 107 | ) a 108 | LEFT JOIN 109 | (-- 符合等级: 110 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2017-01-01' ) b 111 | ON a.accountid = b.accountid 112 | LEFT JOIN 113 | (-- 邀请好友每月投资金额,有效下线人数: 114 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 115 | FROM account_partner_trade 116 | WHERE date(tradetime) BETWEEN '2016-12-01' AND '2016-12-31' AND id in (SELECT id FROM account_partner_trade WHERE amount>5000 ) 117 | GROUP BY 1 ) c 118 | ON a.accountid = c.partnerid ) ddd 119 | ON xxxx.accountid = ddd.accountid 120 | LEFT JOIN 121 | (-- 2017-01月份数据: 122 | SELECT a.accountid as accountid,sums,percent,summ,counts 123 | FROM 124 | (-- 领取点点二重礼的用户及每月奖励金额: 125 | SELECT accountid,sum(money) as sums 126 | FROM 127 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-02-01' 128 | UNION 129 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-02-01' 130 | ) aa 131 | GROUP BY 1 132 | ) a 133 | LEFT JOIN 134 | (-- 符合等级: 135 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2017-02-01' ) b 136 | ON a.accountid = b.accountid 137 | LEFT JOIN 138 | (-- 邀请好友每月投资金额,有效下线人数: 139 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 140 | FROM account_partner_trade 141 | WHERE date(tradetime) BETWEEN '2017-01-01' AND '2017-01-31' AND id in (SELECT id FROM account_partner_trade WHERE amount>5000 ) 142 | GROUP BY 1 ) c 143 | ON a.accountid = c.partnerid ) eee 144 | ON xxxx.accountid = eee.accountid 145 | LEFT JOIN 146 | (-- 2017-02月份数据: 147 | SELECT a.accountid as accountid,sums,percent,summ,counts 148 | FROM 149 | (-- 领取点点二重礼的用户及每月奖励金额: 150 | SELECT accountid,sum(money) as sums 151 | FROM 152 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-03-01' 153 | UNION 154 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-03-01' 155 | ) aa 156 | GROUP BY 1 157 | ) a 158 | LEFT JOIN 159 | (-- 符合等级: 160 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2017-03-01' ) b 161 | ON a.accountid = b.accountid 162 | LEFT JOIN 163 | (-- 邀请好友每月投资金额,有效下线人数: 164 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 165 | FROM account_partner_trade WHERE date(tradetime) BETWEEN '2017-02-01' AND '2017-02-31' 166 | AND tradeid in (SELECT tradeid FROM account_partner_trade WHERE amount>5000 ) 167 | GROUP BY 1 ) c 168 | ON a.accountid = c.partnerid ) fff 169 | ON xxxx.accountid = fff.accountid 170 | LEFT JOIN 171 | (-- 2017-03月份数据: 172 | SELECT a.accountid as accountid,sums,percent,summ,counts 173 | FROM 174 | (-- 领取点点二重礼的用户及每月奖励金额: 175 | SELECT accountid,sum(money) as sums 176 | FROM 177 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-04-01' 178 | UNION 179 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-04-01' 180 | ) aa 181 | GROUP BY 1 182 | ) a 183 | LEFT JOIN 184 | (-- 符合等级: 185 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2017-04-01' ) b 186 | ON a.accountid = b.accountid 187 | LEFT JOIN 188 | (-- 邀请好友每月投资金额,有效下线人数: 189 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 190 | FROM account_partner_trade 191 | WHERE date(tradetime) BETWEEN '2017-03-01' AND '2017-03-31' AND id in (SELECT id FROM account_partner_trade WHERE amount>5000 ) 192 | GROUP BY 1 ) c 193 | ON a.accountid = c.partnerid ) ggg 194 | ON xxxx.accountid = ggg.accountid 195 | LEFT JOIN 196 | (-- 2017-04月份数据: 197 | SELECT a.accountid as accountid,sums,percent,summ,counts 198 | FROM 199 | (-- 领取点点二重礼的用户及每月奖励金额: 200 | SELECT accountid,sum(money) as sums 201 | FROM 202 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-05-01' 203 | UNION 204 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-05-01' 205 | ) aa 206 | GROUP BY 1 207 | ) a 208 | LEFT JOIN 209 | (-- 符合等级: 210 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2017-05-01' ) b 211 | ON a.accountid = b.accountid 212 | LEFT JOIN 213 | (-- 邀请好友每月投资金额,有效下线人数: 214 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 215 | FROM account_partner_trade 216 | WHERE date(tradetime) BETWEEN '2017-04-01' AND '2017-04-31' AND id in (SELECT id FROM account_partner_trade WHERE amount>5000 ) 217 | GROUP BY 1 ) c 218 | ON a.accountid = c.partnerid ) hhh 219 | ON xxxx.accountid = hhh.accountid 220 | LEFT JOIN 221 | (-- 2017-05月份数据: 222 | SELECT a.accountid as accountid,sums,percent,summ,counts 223 | FROM 224 | (-- 领取点点二重礼的用户及每月奖励金额: 225 | SELECT accountid,sum(money) as sums 226 | FROM 227 | (SELECT id,accountid,money FROM account_coupons WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-06-01' 228 | UNION 229 | SELECT id,accountid,money FROM account_coupons_overdue WHERE title in ('点金党收益','点点合伙人收益') AND date(createtime) = '2017-06-01' 230 | ) aa 231 | GROUP BY 1 232 | ) a 233 | LEFT JOIN 234 | (-- 符合等级: 235 | SELECT accountid,percent FROM account_partner_month WHERE date(createtime) = '2017-06-01' ) b 236 | ON a.accountid = b.accountid 237 | LEFT JOIN 238 | (-- 邀请好友每月投资金额,有效下线人数: 239 | SELECT partnerid,sum(amount) as summ,count(DISTINCT accountid) as counts 240 | FROM account_partner_trade 241 | WHERE date(tradetime) BETWEEN '2017-05-01' AND '2017-05-31' AND id in (SELECT id FROM account_partner_trade WHERE amount>5000 ) 242 | GROUP BY 1 ) c 243 | ON a.accountid = c.partnerid ) iii 244 | ON xxxx.accountid = iii.accountid ; 245 | 246 | -- title查询: 247 | SELECT left(title,15) 248 | from 249 | ( 250 | select id,accountid,money,createtime,title 251 | from account_coupons 252 | union 253 | select id,accountid,money,createtime,title 254 | from account_coupons_overdue 255 | ) a 256 | GROUP BY 1 ; 257 | 258 | 259 | 260 | -- 2017-06-15:查看这批用户的持有资产 261 | SELECT id,realname,mobile,sum 262 | FROM 263 | (SELECT id,realname,itemasset+ddbassetwithincome+ddbassetnoincome as sum FROM account ) a 264 | right JOIN 265 | (SELECT accountid,mobile FROM account_mobile WHERE mobile in (15204026599,13219174356,15529617241 )) b 266 | ON a.id = b.accountid ; 267 | 268 | 269 | 270 | -- 回款查询 271 | SELECT * 272 | FROM 273 | ( 274 | SELECT tradeid,title,amount,createtime 275 | FROM account_inout 276 | WHERE biztype = 1 AND inouttype = 2 AND DATE(createtime) BETWEEN "2016-06-01" AND "2017-05-31" 277 | ) a 278 | LEFT JOIN 279 | (SELECT id,totalperiods FROM selfitem ) c 280 | ON a.tradeid = c.id ; 281 | 282 | 283 | SELECT * FROM account_trade WHERE id=100000000000004475 284 | 285 | SELECT tradeid,title,amount,createtime 286 | FROM account_inout 287 | WHERE biztype = 1 AND inouttype = 2 AND DATE(createtime) BETWEEN "2016-06-01" AND "2017-05-31"; 288 | 289 | 290 | SELECT tradeid,title,amount,createtime 291 | FROM account_inout 292 | WHERE title LIKE '%回款%' AND DATE(createtime) BETWEEN "2016-06-01" AND "2017-05-31" 293 | 294 | 295 | 296 | -- 2017-06-14: 297 | -- 凯强 给我导一份 有发生过三次交易以上但近一个月未打开APP的用户的手机号码 298 | SELECT a.accountid,mobile 299 | FROM 300 | (SELECT accountid 301 | FROM account_trade 302 | WHERE biztype IN (1, 3) AND inouttype = 1 AND status = 20 303 | AND accountid NOT IN (SELECT accountid 304 | FROM system_appopenlog 305 | WHERE date(opentime) BETWEEN "2017-05-14" AND "2017-06-14" 306 | GROUP BY 1) 307 | GROUP BY 1 308 | HAVING count(accountid) > 2 309 | ) a 310 | LEFT JOIN 311 | (SELECT accountid,mobile FROM account_mobile ) b 312 | ON a.accountid = b.accountid ; 313 | 314 | 315 | -- 还有一份有账户余额的用户的手机号码 316 | SELECT id,mobile 317 | FROM 318 | (SELECT id,asset FROM account WHERE asset > 0) a 319 | LEFT JOIN 320 | (SELECT accountid,mobile FROM account_mobile ) b 321 | ON a.id = b.accountid ; 322 | 323 | 324 | -- 2017-06-14:加息券 325 | SELECT money,count(*),title 326 | FROM account_coupons 327 | WHERE type=2 328 | GROUP BY 1 329 | ORDER BY 1 ; 330 | 331 | GRANT SELECT ON account_cashout to zhoubijun; 332 | 333 | 334 | 335 | -- 2017-06-13:每月交易额,每月提现金额,每月存量变化金额(准确数据) 336 | SELECT date_format(updatetime,"%Y-%m"),max(date(updatetime)),itemasset+ddbasset 337 | FROM ds_daily_all 338 | WHERE date(updatetime) BETWEEN '2016-06-01' AND '2017-05-31' 339 | GROUP BY 1 ,2; 340 | 341 | SELECT date1,max(date2),sum 342 | FROM 343 | ( 344 | SELECT date_format(updatetime,"%Y-%m") date1,date(updatetime) date2 ,itemasset+ddbasset as sum 345 | FROM ds_daily_all 346 | WHERE date(updatetime) BETWEEN '2016-06-01' AND '2017-05-31' 347 | GROUP BY 1 ,2 348 | ) a 349 | group by 1 ; 350 | 351 | SELECT date1,max(date2),sum 352 | FROM 353 | ( 354 | SELECT date_format(updatetime,"%Y-%m") date1,date(updatetime) date2 ,itemasset+ddbasset as sum 355 | FROM ds_daily_all 356 | WHERE date(updatetime) = '2016-05-31' 357 | GROUP BY 1 ,2 358 | ) a 359 | group by 1 ; 360 | 361 | 362 | 363 | SELECT date_format(updatetime,"%Y-%m"),max(date(updatetime)),itemasset+ddbasset 364 | FROM ds_daily_all 365 | WHERE date(updatetime) = '2016-11-30' ; 366 | 367 | 368 | 369 | show grants for yaokaiqiang; 370 | CREATE USER 'zhoubijun'@'192.168.3.197' IDENDIFIED BY '123456'; 371 | 372 | 373 | -- 2017-06-12 : 凯强 帮我导一份 在pc端交易过的 用户名单 和微信端交易过的用户名单 374 | SELECT a.accountid,mobile 375 | FROM 376 | (SELECT accountid,channel 377 | FROM account_trade 378 | WHERE biztype IN (1, 3) AND inouttype = 1 AND status = 20 AND channel IN ('weixin', 'micromessage', 'micromessenger') 379 | GROUP BY 1 380 | ) a 381 | LEFT JOIN 382 | (SELECT accountid,mobile from account_mobile )b 383 | ON a.accountid = b.accountid ; 384 | 385 | SELECT channel 386 | FROM account_trade 387 | WHERE channel LIKE '%weixin%' 388 | group by 1 ; 389 | 390 | SELECT a.accountid,mobile 391 | FROM 392 | ( 393 | SELECT accountid,channel 394 | FROM account_trade 395 | WHERE biztype in (1,3) AND inouttype=1 AND status=20 AND channel in ('web','pc') 396 | group BY 1 397 | ) a 398 | LEFT JOIN 399 | (SELECT accountid,mobile from account_mobile )b 400 | ON a.accountid = b.accountid ; 401 | 402 | 403 | 404 | 405 | 406 | -- 2017-06-07 :518活动 领券人数 券的成本和交易金额。 407 | SELECT left(title,10) 408 | FROM account_coupons 409 | GROUP BY 1 ; 410 | 411 | SELECT money,count(DISTINCT accountid),count(accountid) 412 | -- SELECT count(DISTINCT accountid),count(accountid),count(accountid) 413 | FROM 414 | (SELECT id,accountid,createtime,money,usemoney,tradeid,type FROM account_coupons WHERE title LIKE '%2017518理财节%' 415 | UNION 416 | SELECT id,accountid,createtime,money,usemoney,tradeid,type FROM account_coupons_overdue WHERE title LIKE '%2017518理财节%' 417 | ) a 418 | group by 1 ; 419 | 420 | 421 | 422 | -- 现金券的使用情况 423 | SELECT money,count(DISTINCT a.accountid),count(a.accountid),sum(couponamount),sum(sum) 424 | -- SELECT date(createtime),count(DISTINCT a.accountid),count(a.accountid),sum(sum) 425 | FROM 426 | (SELECT 427 | id, 428 | accountid, 429 | createtime,couponamount, 430 | amount + assetamount + bonusamount + couponamount AS sum 431 | FROM account_trade 432 | WHERE biztype IN (1, 3) AND inouttype = 1 AND status = 20 433 | GROUP BY 1) a 434 | JOIN 435 | (SELECT 436 | id, 437 | accountid, 438 | tradeid,money 439 | FROM account_coupons 440 | WHERE status = 2 AND type = 1 AND title LIKE '%2017518理财节%') b 441 | ON a.id = b.tradeid 442 | GROUP BY 1; 443 | 444 | -- 加息券的使用: 445 | SELECT money,count(DISTINCT a.accountid),count(a.accountid),sum(totalincome),sum(sum) 446 | FROM 447 | (SELECT 448 | id, 449 | accountid, 450 | tradeid, 451 | createtime,totalincome, 452 | amount AS sum 453 | FROM account_selfitem_coupons 454 | GROUP BY 1) a 455 | JOIN 456 | (SELECT 457 | id, 458 | accountid, 459 | tradeid,money 460 | FROM account_coupons 461 | WHERE status = 2 AND type = 2 AND title LIKE '%2017518理财节%') b 462 | ON a.tradeid = b.tradeid 463 | GROUP BY 1; 464 | 465 | 466 | 467 | 468 | 469 | 470 | -- 2017-05-31 : 凯强 帮我导一下 购买过提薪计划的用户的名单。 471 | SELECT * 472 | FROM 473 | ( 474 | SELECT accountid 475 | FROM account_trade 476 | WHERE biztype in (1,3) AND inouttype=1 AND status=20 477 | AND itemid in (SELECT id FROM selfitem WHERE itemtitle LIKE '%提薪计划%' ) 478 | group BY 1 479 | )a 480 | LEFT JOIN 481 | (SELECT accountid,mobile from account_mobile ) b 482 | ON a.accountid = b.accountid ; 483 | 484 | -- 2017-05-31 485 | SELECT * 486 | FROM 487 | (SELECT id,registtime,asset FROM account WHERE realname IS NULL AND asset > 0 )a 488 | left join 489 | (select accountid,mobile from account_mobile ) b 490 | on a.id = b.accountid ; 491 | 492 | 493 | -- 2017-05-26 :中位数 494 | SELECT num,count(accountid) 495 | FROM 496 | ( 497 | SELECT DATE_FORMAT(createtime,'%Y-%m')as months,accountid,COUNT(*) as num 498 | -- SELECT * 499 | FROM account_trade 500 | WHERE biztype =4 AND inouttype = 2 AND `status` in (6,20) AND DATE(createtime) between '2016-11-01' AND '2017-04-30' 501 | AND accountid in 502 | (SELECT accountid FROM account_trade 503 | WHERE `status` = 20 AND biztype in (1,3) AND inouttype = 1 504 | GROUP BY 1 505 | HAVING count(accountid) >= 3 506 | ) 507 | GROUP BY 1,2 508 | order BY 3 509 | ) a 510 | group by 1 511 | order by 2; 512 | 513 | 514 | 515 | -- 2017-05-26:凯强 帮我看一下 我们三次交易用户及以上 近六个月 每个月的提现次数 516 | 517 | -- 2017-05-23:凯强 帮我看看 去年4月份左右 有发过一批理财金 帮我看下 这批用户的名单(未绑卡交易的) 518 | SELECT a.accountid,mobile,sum 519 | FROM 520 | ( 521 | SELECT accountid 522 | FROM 523 | ( 524 | SELECT 525 | id, 526 | accountid, 527 | money, 528 | createtime, 529 | title 530 | FROM account_coupons 531 | WHERE activityid = 100035 532 | UNION 533 | SELECT 534 | id, 535 | accountid, 536 | money, 537 | createtime, 538 | title 539 | FROM account_coupons_overdue 540 | WHERE activityid = 100035 541 | ) a 542 | WHERE accountid not in (select accountid from account_trade where biztype in (1,3,4) and inouttype=1 and status=20 group by 1 ) 543 | and accountid not in (select accountid from account_independent_authentication where status=20 group by 1 ) 544 | GROUP BY 1 545 | )a 546 | LEFT JOIN 547 | (SELECT accountid,mobile FROM account_mobile )b 548 | ON a.accountid = b.accountid 549 | LEFT JOIN 550 | (SELECT id,sum(asset) as sum FROM account GROUP BY 1) c 551 | ON a.accountid = c.id ; 552 | 553 | -- 2017-05-18: 554 | SELECT a.id,mobile,count,sum 555 | FROM 556 | (SELECT id,channel from account WHERE channel = '518') a 557 | LEFT JOIN 558 | (SELECT accountid,mobile FROM account_mobile ) b 559 | ON a.id = b.accountid 560 | LEFT JOIN 561 | (SELECT accountid,count(*) as count,sum(amount+assetamount+bonusamount+couponamount) as sum 562 | FROM account_trade 563 | WHERE biztype in (1,3) AND inouttype=1 AND status=20 564 | GROUP BY 1) c 565 | ON a.id =c.accountid 566 | 567 | SELECT left(title,10) 568 | FROM account_coupons 569 | WHERE date(createtime)>='2017-05-16' 570 | GROUP BY 1; 571 | 572 | 573 | SELECT money 574 | FROM account_coupons 575 | WHERE title LIKE '%2017518理财节%' -- date(createtime)>='2017-05-16' 576 | GROUP BY 1; 577 | 578 | 579 | 580 | -- 2017-05-16:凯强 给我导一份 持有资产超过10000元的用户名单 & 近一个月未交易的用户名单 并且去重。 581 | select id,sum,mobile 582 | from 583 | (select id,itemasset+ddbassetwithincome+ddbassetnoincome as sum 584 | FROM source.account 585 | HAVING sum >= 10000 586 | -- AND id not in 587 | -- (SELECT accountid FROM source.account_trade 588 | -- WHERE biztype in (1,3) AND inouttype=1 AND status=20 AND date(createtime) BETWEEN '2017-04-16' AND '2017-05-16' 589 | -- GROUP BY 1 ) 590 | ) a 591 | left join 592 | (select accountid,mobile 593 | from account_mobile 594 | ) b 595 | on a.id = b.accountid 596 | order by 2 desc ; 597 | 598 | 599 | SELECT count(DISTINCT accountid) 600 | FROM source.account_trade 601 | WHERE biztype in (1,3) AND inouttype=1 AND status=20 -- AND date(createtime) BETWEEN '2017-04-16' AND '2017-05-16' 602 | 603 | 604 | -- 2017-05-11: 605 | -- 回款用户查询: 606 | select a.accountid,count,sum,mobile 607 | -- select sum(sum) 608 | from 609 | ( 610 | select accountid,count(accountid) count,sum(summ) as sum 611 | -- select * 612 | from 613 | (select accountid,itemid,createtime,amount+assetamount+bonusamount+couponamount as summ 614 | from source.account_trade 615 | where biztype in (1,3) and inouttype=1 and status=20 616 | group by id ) a 617 | join 618 | (select id,nextretdate from source.selfitem where DATE(nextretdate) = '2017-05-14' ) b 619 | on a.itemid = b.id 620 | group by 1 621 | ) a 622 | left join 623 | (select accountid,mobile from source.account_mobile ) b 624 | on a.accountid = b.accountid ; 625 | 626 | 627 | -- test 628 | select accountid,count(accountid) count,sum(summ) as sum 629 | from 630 | (select accountid,itemid,createtime,amount+assetamount+bonusamount+couponamount as summ 631 | from source.account_trade 632 | where biztype in (1) and inouttype=1 and status=20 633 | group by id ) a 634 | join 635 | (select id,nextretdate from source.selfitem where DATE(nextretdate) = '2017-05-13' ) b 636 | on a.itemid = b.id ; 637 | 638 | 639 | select sum(amount+assetamount+bonusamount+couponamount) as summ 640 | from source.account_trade 641 | where biztype in (1) and inouttype=1 and status=20 AND itemid in (select id from selfitem where DATE(nextretdate) = '2017-05-14') 642 | 643 | 644 | select sum(unitprice*totalpcs) from selfitem where DATE(nextretdate) = '2017-05-13'; 645 | 646 | 647 | SELECT date(createtime),sum(amount) 648 | FROM source.account_inout 649 | WHERE biztype=1 AND inouttype=2 and datediff(createtime,NOW()) = -1 650 | GROUP BY 1; 651 | 652 | 653 | SELECT date(createtime),sum(amount) 654 | FROM account_inout 655 | WHERE biztype=1 AND inouttype=2 -- and datediff(createtime,NOW()) = 0 656 | GROUP BY 1; 657 | 658 | 659 | select accountid,amount,title 660 | FROM source.account_inout 661 | WHERE date(createtime)='2017-05-14' AND inouttype=2 AND biztype=1 662 | order by 2 DESC ; 663 | 664 | 665 | -- 2017-05-09:点币大于10万的用户 666 | SELECT mobile 667 | FROM 668 | ( 669 | SELECT accountid,cur_usable_score 670 | FROM source.account_score 671 | WHERE cur_usable_score >= 30000 672 | ) a 673 | LEFT JOIN 674 | (SELECT accountid,mobile FROM source.account_mobile ) b 675 | ON a.accountid =b.accountid ; 676 | 677 | 678 | -- 2017-05-05账户余额总额 679 | SELECT sum(asset) 680 | FROM source.account ; 681 | 682 | 683 | -- 2017-04-28 : 684 | -- 劳动节三天回款用户查询: 685 | select * 686 | from 687 | ( 688 | select date(nextretdate),accountid,count(accountid),sum(summ) 689 | -- select * 690 | from 691 | (select accountid,itemid,createtime,amount+assetamount+bonusamount+couponamount as summ 692 | from account_trade 693 | where biztype in (1,3) and inouttype=1 and status=20 694 | group by id ) a 695 | join 696 | (select id,nextretdate from selfitem where nextretdate between '2017-05-11' and '2017-05-11' ) b 697 | on a.itemid = b.id 698 | group by 1 ,2 699 | ) a 700 | left join 701 | (select accountid,mobile from account_mobile ) b 702 | on a.accountid = b.accountid ; 703 | 704 | 705 | 706 | -- 2017-04-27 : 707 | -- 合伙人一重礼: 708 | select sum(totalincome) 709 | -- select * 710 | from account_partner_monthdetail 711 | where date(createtime) between '2017-04-01' and '2017-04-31' and percent = 0.05 ; 712 | 713 | -- 合伙人二重礼: 714 | select left(title,10),sum(usemoney) 715 | from account_coupons 716 | where date(usetime) between '2017-04-01' and '2017-04-31' and status=2 and type=1 717 | group by 1 718 | order by 2 desc ; 719 | 720 | 721 | select id,accountid,money,createtime from account_coupons where date(createtime) between '2017-04-01' and '2017-04-31' and title like "%点金党收益%" 722 | union 723 | select id,accountid,money,createtime from account_coupons_overdue where date(createtime) between '2017-04-01' and '2017-04-31' and title like "%点金党收益%" ; 724 | 725 | 726 | -- 2017-04-25 : 727 | select ddbassetnoincome+ddbassetwithincome+itemasset as 资产,itemasset,ddbincome+itemincome as 收益, 728 | ddbassetnoincome+ddbassetwithincome+itemasset-ddbincome-itemincome as 本金 729 | from account 730 | where id = 100000000000350134 ; 731 | 732 | 733 | select * 734 | -- select sum(restamount) 735 | from account_selfitem 736 | where accountid = 100000000000350134 and status=5 737 | order by createtime desc ; 738 | 739 | -- 表授权: 740 | grant select on account_selfitem to wangjinyu ; 741 | 742 | 743 | -- 2017-04-24: 744 | -- 1.最近半年交易定期产品的银行卡支付金额: 745 | select case 746 | when totalperiods between 1 and 20 then '15天' 747 | when totalperiods between 21 and 45 then '30天' 748 | when totalperiods between 46 and 75 then '60天' 749 | when totalperiods between 76 and 120 then '90天' 750 | when totalperiods between 121 and 200 then '180天' 751 | when totalperiods > 200 then '360天' end as periods ,count(accountid),count(distinct accountid),sum(sum),sum(summ),sum(sum)/sum(summ) 752 | -- select totalperiods,count(*),count(distinct accountid),sum(sum),sum(summ),sum(sum)/sum(summ) 753 | -- select annualrate,sum(sum),sum(summ),sum(sum)/sum(summ) 754 | from 755 | (select accountid,itemid,createtime,amount as sum,amount+assetamount+bonusamount+couponamount as summ 756 | from account_trade 757 | where biztype in (1,3) and inouttype=1 and status=20 and date(createtime) between '2016-10-24' and '2017-04-23' ) a 758 | join 759 | (select id,totalperiods,annualrate from selfitem ) b 760 | on a.itemid = b.id 761 | group by 1 ; 762 | 763 | 764 | 765 | -- 2.最近半年提现金额统计: 766 | select count(distinct accountid),count(accountid),sum(amount+assetamount+couponamount+bonusamount) 767 | from account_trade 768 | where biztype =4 and inouttype=2 and status in (6,20) and date(createtime) between '2016-10-24' and '2017-04-23' 769 | group by 1 ; 770 | 771 | -- 3.支付手续费 772 | select date(createtime),sum(fee) 773 | from account_trade 774 | where biztype in (1,3) and inouttype=1 and status=20 and date(createtime) between '2016-10-24' and '2017-04-23' 775 | group by 1 ; 776 | 777 | 778 | -- 2017-04-21: 779 | -- 2017年4月份,每天提现5w以上的用户,每天赎回2w以上的用户名单 780 | 781 | select date,a.accountid,sum,mobile,c.realname,d.realname 782 | from 783 | (-- 提现: 784 | select date(createtime) date,accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 785 | from account_trade 786 | where biztype=4 and inouttype =2 and status in (6,20) and date(createtime) between '2017-04-01' and '2017-04-31' 787 | group by 1 , 2 788 | having sum >= 50000 789 | ) a 790 | left join 791 | (select accountid,mobile from account_mobile ) b 792 | on a.accountid = b.accountid 793 | left join 794 | (select id,realname,commandid from account) c 795 | on a.accountid = c.id 796 | left join 797 | (select id,realname from account ) d 798 | on c.commandid = d.id ; 799 | 800 | 801 | 802 | select date,a.accountid,sum,mobile,realname 803 | from 804 | (-- 赎回: 805 | select date(createtime) as date,accountid,sum(amount) as sum 806 | from account_inout 807 | where biztype in (1,3) and inouttype=2 and date(createtime) between '2017-04-01' and '2017-04-31' 808 | group by 1 , 2 809 | having sum >= 20000 ) a 810 | left join 811 | (select accountid,mobile from account_mobile ) b 812 | on a.accountid = b.accountid 813 | left join 814 | (select id,realname from account) c 815 | on a.accountid = c.id; 816 | 817 | 818 | 819 | -- 2017-04-21 :凯强 帮我拉一份 账户余额有钱的 大于10元的名单~要手机号码~ 820 | -- 麻烦给我导一份 账户余额1000元以上的用户的手机号码和账户余额金额。 821 | select id,asset,mobile 822 | from 823 | (select id,asset from account where asset >= 100 ) a 824 | left join 825 | (select accountid,mobile from account_mobile ) b 826 | on a.id = b.accountid 827 | order by 2 desc ; 828 | 829 | -- 1-注册用户 830 | SELECT a.id,channel,registtime,lastlogintime,mobile 831 | FROM 832 | (SELECT id,channel,registtime FROM account WHERE DATE(registtime) = '2017-04-18')a 833 | LEFT JOIN 834 | (SELECT accountid,max(opentime) as lastlogintime FROM system_appopenlog GROUP BY 1)b 835 | ON a.id = b.accountid 836 | left join 837 | (select accountid,mobile from account_mobile ) mm 838 | on a.id = mm.accountid ; 839 | 840 | 841 | -- 2-绑卡失败用户 842 | SELECT a.accountid,realname,gender,registtime,createtime,json 843 | FROM 844 | (SELECT accountid,createtime,json,realname 845 | FROM account_independent_authentication 846 | WHERE DATE(createtime) = '2017-04-18' AND `status` =30 AND json NOT like '%Incorrected card%' )a 847 | JOIN 848 | (SELECT id,gender,registtime FROM ds_account )b 849 | ON a.accountid =b.id ; 850 | 851 | -- 3-首次绑卡成功且绑卡后三天未进行交易 852 | SELECT accountid,realname,if(gender = 1,'男','女')as gender,registtime,createtime 853 | FROM 854 | (SELECT accountid,createtime,realname 855 | FROM account_independent_authentication 856 | WHERE `status` =20 857 | GROUP BY 1)a 858 | JOIN 859 | (SELECT id,gender,registtime FROM ds_account)b 860 | ON a.accountid = b.id 861 | WHERE DATE(createtime) = '2017-04-16' AND accountid not in 862 | (SELECT accountid 863 | FROM account_trade 864 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` =20 AND DATE(createtime) in ('2017-04-16','2017-04-17','2017-04-18') 865 | GROUP BY 1) 866 | ORDER BY createtime; 867 | 868 | 869 | 870 | -- 4-交易失败 871 | SELECT 4-accountid,realname,if(gender = 1,'男','女')as gender,registtime,sum,createtime,json 872 | FROM 873 | ( 874 | SELECT accountid,id,createtime,SUM(amount+bonusamount+couponamount+assetamount) as sum,json 875 | FROM account_trade 876 | WHERE `status` in (5,30) AND DATE(createtime) = '2017-04-18' AND json NOT like '%余额不足%' AND json NOT LIKE '%wrongpwd%' 877 | GROUP BY id 878 | )a 879 | JOIN 880 | (SELECT id,realname,gender,registtime 881 | FROM ds_account)b 882 | ON a.accountid = b.id ; 883 | 884 | -- 5-交易成功且首笔金额大于1000元用户 885 | SELECT accountid,realname,if(gender = 1,'男','女')as gender,registtime,sum,itemid,totalperiods,createtime 886 | FROM 887 | ( 888 | SELECT accountid,createtime,itemid,SUM(amount+bonusamount+couponamount+assetamount) as sum 889 | FROM account_trade 890 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` =20 AND DATE(createtime) = '2017-04-18' 891 | GROUP BY 1 892 | )a 893 | JOIN 894 | (SELECT id,realname,gender,registtime 895 | FROM ds_account)b 896 | on a.accountid = b.id 897 | JOIN 898 | JOIN 899 | (SELECT id,totalperiods 900 | FROM selfitem)c 901 | ON a.itemid = c.id 902 | WHERE sum > 1000 903 | ORDER BY createtime ; 904 | 905 | 906 | SELECT id,accountid,money,usemoney,type,title 907 | FROM account_coupons 908 | WHERE title LIKE "%父亲节%"; 909 | -------------------------------------------------------------------------------- /周报: -------------------------------------------------------------------------------- 1 | 【一、每日用户】 2 | #【1】注册量 3 | SELECT date(registtime),count(id) 4 | FROM da_account WHERE date(registtime)>'2016-01-14' 5 | GROUP BY date(registtime); 6 | -- SELECT count(id) 7 | -- FROM da_account WHERE date(registtime) BETWEEN'2015-12-25' AND '2015-12-31' 8 | -- GROUP BY date(registtime) 9 | #2单日总的绑卡量 10 | SELECT date(tt),count(DISTINCT(aa)) 11 | FROM 12 | ( 13 | SELECT a.id as aa,registtime as tt 14 | from 15 | (SELECT id FROM ds_account WHERE realname is not null) a 16 | JOIN 17 | (SELECT id,registtime FROM da_account) b 18 | ON a.id=b.id 19 | HAVING b.registtime>'2016-01-14' 20 | ) mm 21 | GROUP BY 1; 22 | 23 | #3当日首次交易 24 | SELECT date(tt),count(DISTINCT(aa)) 25 | FROM 26 | (SELECT a.accountid as aa,a.createtime as tt 27 | from 28 | (SELECT accountid,createtime FROM da_account_trade WHERE biztype in(1,3) AND inouttype=1 AND `status`=20 GROUP BY 1) a 29 | JOIN 30 | (SELECT id,registtime FROM da_account) b 31 | ON a.accountid=b.id AND date(a.createtime)=date(b.registtime) 32 | HAVING a.createtime>'2016-01-14') mm 33 | GROUP BY 1; 34 | 35 | #4、单日计算被邀请注册人数 36 | SELECT date(registtime),count(DISTINCT(id)) 37 | FROM da_account 38 | WHERE date(registtime) > '2016-01-14' AND commandid is not null 39 | GROUP BY 1; 40 | #5、被邀请首次交易数; 41 | SELECT date(tt),count(DISTINCT(aa)) 42 | FROM 43 | (SELECT a.accountid as aa,a.createtime as tt 44 | from 45 | (SELECT accountid,createtime FROM da_account_trade WHERE biztype in(1,3) AND inouttype=1 AND `status`=20) a 46 | JOIN 47 | (SELECT id,registtime FROM da_account WHERE commandid is not null) b 48 | ON a.accountid=b.id AND date(a.createtime)=date(b.registtime) 49 | HAVING a.createtime>'2016-01-14') mm 50 | GROUP BY 1; 51 | 52 | #交易次数统计 53 | SELECT dda,count,count(*) 54 | FROM 55 | (SELECT case 56 | -- when count(accountid)=1 then '1次' end as count,date(createtime) as dda 57 | -- when count(accountid)=2 then '2次' end as count,date(createtime) as dda 58 | when count(accountid)>2 then '3次及以上' end as count,date(createtime) as dda 59 | FROM da_account_trade 60 | WHERE biztype in (1,3) AND `status` = 20 AND inouttype = 1 AND date(createtime)>'2016-01-14' 61 | GROUP BY accountid 62 | HAVING count is not null) a 63 | GROUP BY 1,2; 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | #单日总的交易量 72 | SELECT DATE_FORMAT(createtime,'%Y-%m-%d'),count(DISTINCT(accountid)) 73 | FROM da_account_trade 74 | WHERE biztype in (1,3) AND `status` = 20 AND inouttype = 1 75 | AND DATE_FORMAT(createtime,'%Y-%m-%d') >'2015-12-03' 76 | GROUP BY 1; 77 | 78 | #微信交易用户【????】 79 | SELECT date(createtime),count(accountid) 80 | FROM youyu_account_trade 81 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)>'2015-11-12' 82 | AND accountid in (SELECT id FROM youyu_account WHERE channel = 'weixin') 83 | GROUP BY date(createtime); 84 | 85 | SELECT count(*) 86 | FROM 87 | (SELECT * FROM youyu_account_trade WHERE date(paysuccesstime)='2015-11-14' and biztype in (1,3) AND inouttype=1 AND `status`=20) a 88 | LEFT JOIN 89 | (SELECT * FROM youyu_account) b 90 | ON a.accountid=b.id 91 | WHERE a.biztype in (1,3) AND a.`status`=20 AND a.inouttype=1 AND date(a.paysuccesstime)='2015-11-12' AND b.channel='weixin'; 92 | 93 | SELECT date(paysuccesstime),count(*) 94 | FROM youyu_account_trade 95 | WHERE biztype in(1,3) AND inouttype=1 AND `status`=20 AND date(paysuccesstime)='2015-11-13' 96 | AND channel in (SELECT channel FROM youyu_account_trade WHERE channel ='weixin') 97 | GROUP BY date(paysuccesstime); 98 | 99 | 【二、每日交易】 100 | 【当日交易额——点点宝交易额——优选理财交易额】 101 | SELECT a.dda,a.sum,b.sum,c.sum 102 | from 103 | (#每日交易总额 104 | SELECT date(createtime)as dda,sum(amount+assetamount+bonusamount+couponamount)as sum 105 | FROM da_account_trade 106 | WHERE biztype in (1,3) AND `status`=20 AND inouttype=1 AND date(createtime)>'2016-01-14' 107 | GROUP BY date(createtime) ) a 108 | JOIN 109 | (#每日点点宝交易总额 110 | SELECT date(createtime) as dda,sum(amount+assetamount+bonusamount+couponamount) as sum 111 | FROM da_account_trade 112 | WHERE biztype=3 AND `status`=20 AND inouttype=1 AND date(createtime)>'2016-01-14' 113 | GROUP BY 1 ) b 114 | ON a.dda=b.dda 115 | JOIN 116 | (#每日优选理财交易总额 117 | SELECT date(createtime) as dda,sum(amount+assetamount+bonusamount+couponamount)as sum 118 | FROM da_account_trade 119 | WHERE biztype=1 AND `status`=20 AND inouttype=1 AND date(createtime)>'2016-01-14' 120 | GROUP BY 1) c 121 | ON b.dda=c.dda 122 | GROUP BY 1; 123 | 【新用户交易额——老用户交易额】 124 | SELECT a.aaa,a.xin,b.lao 125 | FROM 126 | (SELECT date(createtime) as aaa,sum(amount+assetamount+bonusamount+couponamount)as xin 127 | FROM da_account_trade 128 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 AND date(paysuccesstime)='2016-01-21' 129 | AND accountid not IN (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 130 | and paysuccesstime < '2016-01-21')) a 131 | #每天新用户交易额s 132 | JOIN 133 | (SELECT date(createtime) as bbb,sum(amount+assetamount+bonusamount+couponamount)as lao 134 | FROM da_account_trade 135 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 136 | AND date(createtime)='2016-01-21' 137 | AND accountid IN (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 138 | and date(createtime) < '2016-01-21')) b#每天老用户交易额 139 | ON a.aaa=b.bbb; 140 | 141 | 【一次交易额——二次交易额——三次以上交易额】 142 | #交易次数为1,2,3及大于三次的用户数统计: 143 | SELECT dda,sum(sum) 144 | FROM 145 | (SELECT date(createtime) as dda,count(accountid),sum(amount+assetamount+bonusamount+couponamount) as sum 146 | FROM da_account_trade 147 | WHERE biztype in (1,3) AND `status`=20 AND inouttype=1 AND date(createtime)>'2016-01-14' 148 | GROUP BY accountid 149 | HAVING count(accountid)=1) aa 150 | GROUP BY 1; 151 | 测试 152 | SELECT dda,count(accountid),sum(sum) 153 | FROM 154 | (SELECT accountid,count(accountid),date(createtime)as dda,sum(amount+assetamount+bonusamount+couponamount) as sum 155 | FROM da_account_trade 156 | WHERE biztype in (1,3) AND `status`=20 AND inouttype=1 AND date(createtime)>'2016-01-14' 157 | GROUP BY 1 158 | HAVING count(accountid)=2) aa 159 | GROUP BY 1,2 160 | 161 | 【点点宝赎回金额——点点宝净流入——当日提现额——平台资金净流入】 162 | SELECT a.dda,a.sum,b.sum 163 | from 164 | (#点点宝赎回金额 165 | SELECT date(createtime) as dda,sum(amount+assetamount+bonusamount+couponamount) as sum 166 | FROM da_account_trade 167 | WHERE biztype=3 AND `status`=20 AND inouttype=2 AND date(createtime)>'2016-01-14' 168 | GROUP BY date(createtime)) a 169 | JOIN 170 | (#当日提现额 171 | SELECT date(createtime) as dda,sum(amount+assetamount+bonusamount+couponamount) as sum 172 | FROM da_account_trade 173 | WHERE biztype =4 AND `status` in(20,6,5) AND inouttype=2 AND date(createtime)>'2016-01-14' 174 | GROUP BY date(createtime) ) b 175 | ON a.dda=b.dda 176 | GROUP BY 1; 177 | 178 | 【三、支付】 179 | #每日支付成功数量 180 | SELECT date(createtime),count(*) 181 | FROM da_account_trade 182 | WHERE `status`=20 AND biztype in (1,3) AND inouttype=1 AND date(createtime)>'2016-01-14' 183 | GROUP BY 1; 184 | #每日支付失败笔数 185 | SELECT date(createtime),count(*) 186 | FROM da_account_trade 187 | WHERE `status`=30 AND biztype in (1,3) AND inouttype=1 AND date(createtime)>'2016-01-14' 188 | GROUP BY 1; 189 | #ceshi 190 | SELECT * 191 | FROM youyu_account_trade 192 | WHERE `status`=30 AND biztype in (1,3,4) AND inouttype in (1,2) 193 | AND DATE_FORMAT(createtime,'%Y-%m')='2015-11'; 194 | 195 | #每日支付成功人数 196 | SELECT date(createtime),count(DISTINCT(accountid)) 197 | FROM da_account_trade 198 | WHERE `status`=20 AND biztype in (1,3) AND inouttype=1 AND date(createtime)>'2016-01-14' 199 | GROUP BY 1; 200 | #当天支付金额 201 | SELECT date(createtime),sum(amount+assetamount+bonusamount+couponamount) as 交易额 202 | FROM da_account_trade 203 | WHERE `status`=20 AND biztype in (1,3) AND inouttype=1 AND date(createtime)>'2016-01-14' 204 | GROUP BY 1; 205 | 206 | 207 | 【平均支付成功率】该怎么计算??? 208 | 209 | SELECT `status`,count(*) 210 | FROM da_account_trade 211 | WHERE inouttype=1 AND date(createtime)='2015-11-13' 212 | GROUP BY `status`; 213 | 214 | SELECT count(*) 215 | FROM youyu_account_trade 216 | WHERE inouttype=1 AND biztype in (1,3) AND date(createtime)='2015-11-20' 217 | 218 | SELECT DISTINCT(`status`) 219 | FROM youyu_account_trade 220 | WHERE date(createtime)='2015-11-20' 221 | 222 | 【四、奖励】 223 | SELECT a.dda,a.sum,b.sum,c.sum,d.sum,e.sum 224 | from 225 | (#红包发包 226 | SELECT date(createtime) as dda,count(id),sum(bonus) as sum 227 | FROM account_bonus 228 | WHERE date(createtime)>'2016-01-07' AND inouttype = 1 229 | GROUP BY 1) a 230 | JOIN 231 | (#红包使用 232 | SELECT DATE_FORMAT(createtime,'%Y-%m-%d') as dda,sum(bonusamount) as sum 233 | FROM da_account_trade 234 | WHERE DATE_FORMAT(createtime,'%Y-%m-%d')>'2016-01-07' AND biztype in (1,3) AND `status`=20 AND inouttype=1 235 | GROUP BY 1) b 236 | ON a.dda=b.dda 237 | JOIN 238 | (#发放现金券 239 | SELECT date(createtime) as dda,sum(money) as sum 240 | FROM account_coupons 241 | WHERE date(createtime)>'2016-01-07' 242 | GROUP BY 1) c 243 | ON b.dda=c.dda 244 | JOIN 245 | (#现金券的使用 246 | SELECT date(createtime) as dda,sum(couponamount) as sum 247 | FROM da_account_trade 248 | WHERE date(createtime)>'2016-01-07' 249 | AND inouttype = 1 AND `status` = 20 AND biztype in (1,3) 250 | GROUP BY 1) d 251 | ON c.dda=d.dda 252 | JOIN 253 | (#现金券的过期 254 | SELECT date(endtime) as dda,sum(money) as sum 255 | FROM account_coupons_expire 256 | WHERE date(endtime)>'2016-01-07' 257 | GROUP BY 1) e 258 | ON d.dda=e.dda 259 | GROUP BY 1; 260 | 261 | 262 | 263 | 【奖励】11月份 264 | #红包发包 265 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(bonus) 266 | FROM account_bonus 267 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2015-11' AND inouttype = 1 268 | GROUP BY 1; 269 | #红包使用 270 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(bonusamount) 271 | FROM youyu_account_trade 272 | WHERE DATE_FORMAT(createtime,'%Y-%m')>'2015-07' AND biztype in (1,3) AND `status`=20 AND inouttype=1 273 | GROUP BY 1; 274 | #发放现金券 275 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(money) 276 | FROM account_coupons 277 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2015-11' 278 | GROUP BY 1; 279 | #现金券的使用 280 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(couponamount) 281 | FROM youyu_account_trade 282 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2015-11' AND inouttype = 1 AND `status` = 20 AND biztype in (1,3) 283 | GROUP BY 1; 284 | #现金券的过期 285 | SELECT DATE_FORMAT(endtime,'%Y-%m'),sum(money) 286 | FROM account_coupons_expire 287 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2015-11' 288 | GROUP BY 1; 289 | 290 | ###上周奖励合计 291 | #上周红包发放 292 | SELECT sum(bonus) 293 | FROM account_bonus 294 | WHERE date(createtime)>'2015-11-05' AND date(createtime) < '2015-11-13' AND inouttype = 1; 295 | #使用红包 296 | SELECT sum(bonusamount) 297 | FROM youyu_account_trade 298 | WHERE date(createtime)>'2015-11-05' AND date(createtime) < '2015-11-13' AND inouttype = 1 AND `status` = 20 AND biztype in (1,3); 299 | #发放现金券 300 | SELECT sum(money) 301 | FROM account_coupons 302 | WHERE date(createtime)>'2015-11-05' AND date(createtime) < '2015-11-13'; 303 | #现金券的使用 304 | SELECT sum(usemoney) 305 | FROM account_coupons_used 306 | WHERE date(usetime)>'2015-11-05' AND date(usetime) < '2015-11-13'; 307 | #上周现金券过期 308 | SELECT sum(money) 309 | FROM account_coupons_expire 310 | WHERE date(endtime)>'2015-11-05' AND date(endtime) < '2015-11-13' ; 311 | 312 | 313 | 314 | #渠道注册人数 315 | SELECT channel,count(id) as count 316 | FROM youyu_account 317 | WHERE DATE_FORMAT(registtime,'%Y-%m-%d') = '2015-11-23' 318 | GROUP BY channel 319 | ORDER BY count DESC; 320 | #渠道绑卡人数 321 | SELECT channel,count(channel) 322 | FROM youyu_account_trade 323 | WHERE createtime>'2015-11-13' AND createtime<'2015-11-19' AND `status` = 20 AND inouttype = 1 and biztype=4 324 | and accountid in (SELECT id FROM youyu_account WHERE registtime>'2015-11-12' AND registtime<'2015-11-20' ) 325 | GROUP BY channel; 326 | #渠道交易人数 327 | SELECT channel,count(DISTINCT(accountid)) 328 | FROM youyu_account_trade 329 | WHERE createtime>'2015-11-12' AND createtime<'2015-11-20' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 330 | AND channel IN (SELECT channel FROM youyu_account WHERE registtime>'2015-11-12' AND registtime<'2015-11-20') 331 | AND accountid in (SELECT id FROM youyu_account WHERE registtime>'2015-11-12' AND registtime<'2015-11-20') 332 | GROUP BY channel; 333 | ###关联产品表,遍历利率annualrate 334 | SELECT b.annualrate,count(DISTINCT(a.itemid)),sum(a.amount+a.bonusamount+a.couponamount+a.assetamount) as sum 335 | FROM 336 | (SELECT * FROM youyu_account_trade WHERE DATE_FORMAT(createtime,'%Y-%m-%d') BETWEEN '2015-11-13' AND'2015-11-19' AND biztype in (1,3) AND inouttype = 1 AND `status`=20) a 337 | LEFT JOIN 338 | (SELECT * FROM selfitem WHERE starttime > '2015-11-13' AND starttime < '2015-11-19') b 339 | ON a.itemid = b.id 340 | GROUP BY b.annualrate; 341 | #11-13--11-19交易总额 342 | SELECT sum(amount+bonusamount+couponamount+assetamount) 343 | FROM youyu_account_trade 344 | WHERE DATE_FORMAT(createtime,'%Y-%m-%d') BETWEEN '2015-11-13' AND'2015-11-19' AND biztype in (1,3) AND inouttype = 1 AND `status`=20 345 | 346 | ###关联产品表,遍历期限totalperiods: 347 | SELECT b.totalperiods,count(DISTINCT(itemid)),sum(a.amount+a.bonusamount+a.couponamount+a.assetamount) as sum 348 | FROM 349 | (SELECT * FROM youyu_account_trade WHERE DATE_FORMAT(createtime,'%Y-%m-%d') BETWEEN '2015-11-13' AND'2015-11-19' AND biztype in (1,3) AND inouttype = 1 AND `status`=20) a 350 | LEFT JOIN 351 | (SELECT * FROM selfitem WHERE starttime>'2015-11-12' AND starttime<'2015-11-20') b 352 | ON a.itemid = b.id 353 | GROUP BY b.totalperiods; 354 | 355 | 356 | #每种渠道交易额计算 357 | SELECT channel,sum(amount+couponamount+assetamount+bonusamount) as sum 358 | FROM youyu_account_trade 359 | WHERE paysuccesstime>'2015-11-12' AND paysuccesstime<'2015-11-20' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 360 | AND channel IN (SELECT DISTINCT(channel) FROM youyu_account WHERE paysuccesstime>'2015-11-12' AND paysuccesstime<'2015-11-20')AND accountid in (SELECT DISTINCT(id) FROM youyu_account WHERE paysuccesstime>'2015-11-12' AND paysuccesstime<'2015-11-20') 361 | GROUP BY channel 362 | ORDER BY sum DESC; 363 | 364 | SELECT channel,sum(amount+couponamount+assetamount+bonusamount) as sum 365 | FROM youyu_account_trade 366 | WHERE DATE_FORMAT(paysuccesstime,'%Y-%m-%d')BETWEEN '2015-11-13' AND '2015-11-19' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 367 | GROUP BY channel 368 | ORDER BY sum DESC; 369 | 370 | #交易次数 371 | SELECT DISTINCT(b.itemid),count(b.accountid),sum(amount+bonusamount+couponamount+assetamount) as sum 372 | FROM 373 | (SELECT id,channel FROM youyu_account WHERE channel = 'quanmama' AND registtime > '2015-10-28' ) a 374 | LEFT JOIN 375 | (SELECT * FROM youyu_account_trade WHERE createtime >'2015-10-28' AND inouttype = 1 AND `status` = 20 AND biztype in (1,3)) b 376 | ON a.id=b.accountid 377 | GROUP BY b.itemid 378 | HAVING count(b.accountid) in (1,2,3) 379 | ORDER BY sum DESC; 380 | 381 | SELECT * 382 | FROM selfitem 383 | WHERE id = '100000000000002262' 384 | 385 | SELECT count(*) 386 | FROM youyu_account 387 | WHERE registtime < '2015-11-18' 388 | 389 | 390 | 【五、渠道分布】 391 | SELECT a.channel,a.count,b.count,c.count,b.count/a.count,c.count/b.count,c.count/a.count 392 | FROM 393 | (#1、各渠道注册人数 394 | SELECT channel,count(id) as count 395 | FROM da_account 396 | WHERE date(registtime)>'2016-01-14' 397 | GROUP BY 1 398 | ORDER BY 2 DESC) a 399 | LEFT JOIN 400 | (#2、各渠道绑卡查询 401 | SELECT channel,count(realname) as count 402 | FROM ds_account 403 | WHERE date(registtime)>'2016-01-14' 404 | AND id in (SELECT id FROM da_account where date(registtime)>'2016-01-14') 405 | GROUP BY 1) b 406 | ON a.channel=b.channel 407 | LEFT JOIN 408 | (#3、各渠道交易人数查询 409 | SELECT channel,count(accountid) as count 410 | FROM 411 | (SELECT id,channel 412 | FROM ds_account 413 | WHERE date(registtime)>'2016-01-14' 414 | AND id in (SELECT id FROM da_account where date(registtime)>'2016-01-14') 415 | GROUP BY 1) a 416 | JOIN 417 | (SELECT accountid 418 | FROM da_account_trade 419 | WHERE date(createtime)>'2016-01-14' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 420 | GROUP BY 1) b 421 | ON a.id=b.accountid 422 | GROUP BY 1) c 423 | ON a.channel=c.channel 424 | GROUP BY 1 425 | ORDER BY 2 DESC; 426 | 427 | 428 | 4、每种渠道交易额计算 429 | SELECT b.channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) 430 | from 431 | (SELECT accountid,channel,amount,assetamount,bonusamount,couponamount 432 | FROM da_account_trade 433 | WHERE date(createtime)>'2016-01-14' AND `status` = 20 AND biztype in (1,3) AND inouttype=1) a 434 | JOIN 435 | (SELECT id,channel FROM da_account WHERE date(registtime)>'2016-01-14') b 436 | on a.accountid=b.id 437 | GROUP BY 1 438 | ORDER BY 2 DESC; 439 | 440 | 441 | 442 | 443 | 444 | SELECT date(createtime),count(DISTINCT(accountid)) 445 | FROM da_account_trade 446 | WHERE biztype=4 AND inouttype=1 AND `status`=20 AND date(createtime)>'2015-12-10' 447 | GROUP BY 1; 448 | 449 | 450 | 451 | SELECT channel,count(DISTINCT(accountid)) 452 | FROM da_account_trade 453 | WHERE biztype =4 AND inouttype=1 AND `status`=20 AND date(createtime)>'2015-12-10' 454 | GROUP BY 1; 455 | 456 | 457 | SELECT * 458 | FROM da_account_trade 459 | WHERE channel ='micromessenger' AND date(createtime)>'2015-12-10' 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 【从2014-07-07开始,各渠道渠道用户转化率 近6个月的】 469 | 470 | SELECT aaa.channel,aaa.count,bbb.count,ccc.count 471 | ,bbb.count/aaa.count,ccc.count/bbb.count,ccc.count/aaa.count 472 | from 473 | ( 474 | #各渠道注册用户 475 | SELECT channel,count(id) as count 476 | FROM da_account 477 | WHERE date(registtime)>'2015-12-31' 478 | GROUP BY 1 479 | ORDER BY 2 DESC ) aaa 480 | LEFT JOIN 481 | ( 482 | #各渠道绑卡用户 483 | SELECT channel,count(DISTINCT(realname)) as count 484 | FROM ds_account 485 | WHERE date(registtime) BETWEEN '2016-01-01' AND '2016-01-07' 486 | GROUP BY 1 487 | ORDER BY 2 DESC ) bbb 488 | ON aaa.channel=bbb.channel 489 | LEFT JOIN 490 | ( 491 | #各渠道交易用户 492 | SELECT b.channel as channel,count(DISTINCT(accountid)) as count 493 | FROM 494 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 495 | AND accountid in (SELECT id FROM ds_account WHERE realname is not null AND date(registtime)>'2015-12-31' )) a 496 | JOIN 497 | (SELECT id,channel 498 | FROM da_account 499 | WHERE date(registtime)>'2015-12-31' ) b 500 | on a.accountid=b.id 501 | GROUP BY 1 502 | ORDER BY 2 DESC ) ccc 503 | ON bbb.channel=ccc.channel 504 | GROUP BY 1 505 | ORDER BY 2 DESC; 506 | 507 | 508 | 【六、产品分布】 509 | #交易表关联产品表,遍历利率annualrate 510 | SELECT b.annualrate,count(DISTINCT(a.itemid))as count,sum(a.amount+a.bonusamount+a.couponamount+a.assetamount) as sum 511 | FROM 512 | (SELECT * FROM da_account_trade WHERE DATE_FORMAT(createtime,'%Y-%m-%d')>'2016-01-14' 513 | AND biztype in (1,3) AND inouttype = 1 AND `status`=20) a 514 | LEFT JOIN 515 | (SELECT * FROM selfitem) b 516 | ON a.itemid = b.id 517 | GROUP BY b.annualrate; 518 | 519 | ###交易表关联产品表,遍历期限totalperiods: 520 | SELECT b.totalperiods,count(DISTINCT(itemid)),sum(a.amount+a.bonusamount+a.couponamount+a.assetamount) as sum 521 | 522 | -- SELECT CASE 523 | -- WHEN totalperiods>0 AND totalperiods<21 THEN '15' 524 | -- WHEN totalperiods>20 AND totalperiods<46 THEN '30' 525 | -- WHEN totalperiods>45 AND totalperiods<76 THEN '60' 526 | -- WHEN totalperiods>75 AND totalperiods<136 THEN '90' 527 | -- WHEN totalperiods>135 AND totalperiods<200 THEN '180' 528 | -- WHEN totalperiods>200 THEN '360天' end as period,count(DISTINCT(id)),sum(amount+assetamount+bonusamount+couponamount) 529 | -- 530 | -- -- SELECT totalperiods,count(id),sum(amount+assetamount+bonusamount+couponamount) 531 | FROM 532 | (SELECT accountid,itemid,amount,assetamount,bonusamount,couponamount FROM da_account_trade 533 | WHERE DATE_FORMAT(createtime,'%Y-%m-%d')>'2016-01-14' 534 | AND biztype in (1,3) AND inouttype = 1 AND `status`=20) a 535 | LEFT JOIN 536 | (SELECT totalperiods,id FROM selfitem) b 537 | ON a.itemid = b.id 538 | GROUP BY 1 539 | ORDER BY 1 DESC; 540 | -------------------------------------------------------------------------------- /平均花费时长: -------------------------------------------------------------------------------- 1 | SELECT count(accountid),sum(diff),sum(diff)/count(accountid) 2 | FROM 3 | (SELECT a.accountid,a.createtime,b.createtime,timestampdiff(day,b.createtime,a.createtime) as diff 4 | FROM 5 | (SELECT accountid,createtime 6 | FROM da_account_trade 7 | where biztype in (1,3) AND inouttype=1 AND `status`=20 8 | AND accountid in 9 | (SELECT id 10 | FROM da_account 11 | WHERE date(registtime)>'2015-5-31' 12 | AND channel NOT in ('dandanzuan','kumi','dandanzuan','xiaoniao','8868','dianju')) 13 | GROUP BY 1) a 14 | JOIN 15 | (SELECT accountid,createtime 16 | FROM da_account_trade 17 | WHERE biztype=4 AND inouttype=1 AND `status`=20 18 | AND accountid in (SELECT id 19 | FROM ds_account 20 | WHERE date(registtime)>'2015-05-31' 21 | AND iDdate is not null 22 | AND channel NOT in ('dandanzuan','kumi','dandanzuan','xiaoniao','8868','dianju')) 23 | GROUP BY 1) b 24 | ON a.accountid=b.accountid 25 | ORDER BY 4 DESC) shichang; 26 | 27 | 28 | # 29 | SELECT count(accountid),sum(diff),sum(diff)/count(accountid) 30 | FROM 31 | (SELECT a.accountid,a.createtime as atime,b.createtime,timestampdiff(day,b.createtime,a.createtime) as diff 32 | FROM 33 | (SELECT accountid,createtime 34 | FROM da_account_trade 35 | where biztype in (1,3) AND inouttype=1 AND `status`=20 36 | AND accountid in 37 | (SELECT id 38 | FROM da_account 39 | WHERE date(registtime)>'2015-5-31' 40 | AND commandid is null 41 | AND channel NOT in ('dandanzuan','kumi','dandanzuan','xiaoniao','8868','dianju')) 42 | GROUP BY 1) a 43 | LEFT JOIN 44 | (SELECT accountid,createtime 45 | FROM da_account_trade 46 | WHERE biztype=4 AND inouttype=1 AND `status`=20 47 | AND accountid in (SELECT accountid 48 | FROM da_account_trade 49 | where biztype in (1,3) AND inouttype=1 AND `status`=20 50 | AND accountid in 51 | (SELECT id 52 | FROM da_account 53 | WHERE date(registtime)>'2015-5-31' AND commandid is null 54 | AND channel NOT in ('dandanzuan','kumi','dandanzuan','xiaoniao','8868','dianju')) 55 | GROUP BY 1)) b 56 | ON a.accountid=b.accountid 57 | GROUP BY 1 58 | ORDER BY 4 DESC) shichang; 59 | -------------------------------------------------------------------------------- /当日注册用户中的交易用户数量: -------------------------------------------------------------------------------- 1 | SELECT date(tt),count(DISTINCT(aa)) 2 | FROM 3 | (SELECT a.accountid as aa,a.createtime as tt 4 | from 5 | (SELECT accountid,createtime FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20) a 6 | JOIN 7 | (SELECT id,registtime FROM da_account) b 8 | ON a.accountid=b.id AND date(a.createtime)=date(b.registtime) 9 | HAVING a.createtime>'2015-12-25') mm 10 | GROUP BY 1; 11 | -------------------------------------------------------------------------------- /微信端每日交易数据: -------------------------------------------------------------------------------- 1 | SELECT ddaa,zhuce,count1,count2,count3,bangka,count4,count5,sum 2 | FROM 3 | (-- 注册: 4 | SELECT date(registtime) ddaa,count(id) as zhuce FROM account WHERE channel in ("weixin","micromessage","micromessenger") and date(registtime)>'2016-07-31' GROUP BY 1 ) a 5 | LEFT JOIN 6 | (SELECT date(registtime) dda,count(id) as count1 FROM account WHERE channel in ("weixin") GROUP BY 1 ) b 7 | ON a.ddaa=b.dda 8 | LEFT JOIN 9 | (SELECT date(registtime) dda,count(id) as count2 FROM account WHERE channel in ("micromessage") GROUP BY 1 ) c 10 | ON a.ddaa=c.dda 11 | LEFT JOIN 12 | (SELECT date(registtime) dda,count(id) as count3 FROM account WHERE weixinopenid is not null GROUP BY 1 ) d 13 | ON a.ddaa=d.dda 14 | LEFT JOIN 15 | (-- 绑卡: 16 | SELECT date(createtime) as dda,count(accountid) as bangka 17 | FROM account_independent_authentication 18 | WHERE `status`=20 AND accountid in (SELECT id FROM account WHERE channel in ("weixin","micromessage","micromessenger") GROUP BY 1 ) 19 | GROUP BY 1 ) e 20 | ON a.ddaa=e.dda 21 | LEFT JOIN 22 | (-- 交易: 23 | SELECT date(createtime) as dda,count(DISTINCT accountid) as count4,count(accountid)as count5,sum(amount+assetamount+bonusamount+couponamount) as sum 24 | FROM account_trade 25 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND channel in ("weixin","micromessage","micromessenger") 26 | GROUP BY 1 ) f 27 | ON a.ddaa=f.dda 28 | -------------------------------------------------------------------------------- /拼团: -------------------------------------------------------------------------------- 1 | 【分析思路】 2 | 1、正在申请的团队:有多少正在申请————每个团队现有的团员数量————每个团队团长的id————当前的屏图案行为正处在哪个阶段————其中在之前有过拼团行为的团长 3 | ————之前有过拼团行为的团长申请失败的原因在哪里 4 | 2、拼团过期的团队:有多少团队拼团过期————拼团过期的原因是什么???————这些团长中之前有过交易行为的数量有多少————没有交易行为的数量有多少————每个团队的团员数量 5 | ————每个团队拼团所处的阶段————邀请来的团长有多少人————渠道自己注册来的团长有多少人 6 | 3、拼团成功的团队:多少团队拼团成功————每个团队的交易金额——每个团队每个用户的交易情况——每个团队的收益情况 7 | 8 | 9 | 10 | 11 | 【拼团成功】 12 | 拼团成功的团长信息+团队信息 13 | SELECT accountid,createtime,count(accountid) 14 | FROM activity_group 15 | -- WHERE `status`=3 16 | GROUP BY 1 17 | HAVING count(accountid) > 1 18 | ORDER BY 2 DESC ; 19 | 20 | 成团各团成交额 21 | SELECT groupid,sum(amount) 22 | FROM activity_group_detail 23 | WHERE groupid in (SELECT id FROM activity_group WHERE `status`=3) 24 | GROUP BY 1; 25 | 26 | SELECT groupid,count(accountid),sum(amount) 27 | FROM activity_group_detail 28 | WHERE groupid in (SELECT id FROM activity_group WHERE `status`=4) 29 | GROUP BY 1 30 | ORDER BY 3 DESC; 31 | 32 | 短信推送之后申请拼团的数量: 33 | SELECT accountid,createtime 34 | FROM activity_group 35 | WHERE `status`=4 AND createtime>'2016-01-10 12:58:51' AND createtime<'2016-01-11 23:59:59' 36 | -- WHERE `status`=4 AND DATE_FORMAT(createtime,'%Y-%m-%d %T') between '2016-01-07 16:53:14' and '2016-01-08 23:59:59'; 37 | WHERE `status`=4 AND EXTRACT(year_second FROM "%Y-%m-%d %H-%i-%s") between "2016-01-07 16:53:14" and "2016-01-08 23:59:59"; 38 | 39 | 回头用户查询 40 | SELECT accountid FROM activity_group 41 | WHERE createtime<'2016-01-07 16:53:14' 42 | AND accountid in (SELECT accountid FROM activity_group 43 | WHERE `status`=4 AND createtime>'2016-01-07 16:53:14' AND createtime<'2016-01-08 23:59:59') 44 | 45 | 46 | 47 | 48 | SELECT EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03"); 49 | SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %H-%i-%s'); 50 | SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %T'); 51 | 52 | 各过期团队成员情况: 53 | SELECT groupid,count(accountid) 54 | FROM activity_group_detail 55 | WHERE groupid in (SELECT id FROM activity_group WHERE `status`=4) 56 | GROUP BY 1 57 | ORDER BY 2 DESC; 58 | 59 | 正在拼团的团队的成员数: 60 | SELECT groupid,count(accountid) 61 | FROM activity_group_detail 62 | WHERE groupid in (SELECT id FROM activity_group WHERE `status`=1 GROUP BY 1) 63 | GROUP BY 1 64 | ORDER BY 2 DESC; 65 | 正在拼团的团队的成员数+每个团团长的id 66 | SELECT a.id,count(b.accountid),a.accountid,a.createtime 67 | FROM 68 | (SELECT id,accountid,createtime 69 | FROM activity_group 70 | WHERE `status`=1 71 | GROUP BY 1) a 72 | JOIN 73 | (SELECT groupid,accountid 74 | FROM activity_group_detail) b 75 | ON a.id=b.groupid 76 | GROUP BY 1; 77 | 78 | (正在拼团的团长在之前有没有申请过建团:) 79 | SELECT accountid,count(accountid) 80 | FROM activity_group 81 | WHERE date(createtime) BETWEEN '2015-12-31' AND '2015-01-06' 82 | -- AND accountid in (SELECT a.accountid 83 | -- FROM 84 | -- (SELECT id,accountid,createtime 85 | -- FROM activity_group 86 | -- WHERE `status`=1 87 | -- GROUP BY 1) a 88 | -- JOIN 89 | -- (SELECT groupid,accountid 90 | -- FROM activity_group_detail) b 91 | -- ON a.id=b.groupid 92 | -- GROUP BY 1) 93 | GROUP BY 1 94 | ORDER BY 2 DESC; 95 | 96 | 97 | 拼团成功团队的团队交易明细 98 | SELECT accountid,sum(amount) 99 | FROM activity_group_detail 100 | WHERE accountid in (SELECT accountid FROM activity_group WHERE `status`=4) AND `status`=1 101 | GROUP BY 1 102 | ORDER BY 2 DESC; 103 | 104 | 各拼团成功团队的交易情况 105 | SELECT groupid,sum(amount) 106 | FROM activity_group_detail 107 | WHERE groupid in (SELECT groupid FROM activity_group_detail 108 | WHERE accountid in (SELECT accountid FROM activity_group WHERE `status`=4) AND `status`=1) 109 | group BY 1 110 | 111 | 112 | 113 | 【拼团失败---已经过期】 114 | SELECT date(createtime),count(DISTINCT(accountid)) 115 | SELECT accountid 116 | FROM activity_group 117 | WHERE `status`=4 118 | GROUP BY 1; 119 | 120 | 121 | SELECT groupid,count(accountid) 122 | FROM activity_group_detail 123 | WHERE `status`=1 124 | -- AND groupid in (SELECT id FROM a WHERE `status`=4) 125 | GROUP BY 1 126 | ORDER BY 2 DESC; 127 | 128 | 129 | 130 | 131 | SELECT groupid,createtime,count(accountid) 132 | FROM activity_group_detail 133 | -- WHERE `status`=1 134 | GROUP BY 1 135 | ORDER BY 3 DESC 136 | 137 | SELECT DISTINCT(accountid) 138 | FROM activity_group 139 | WHERE `status`!=3 140 | 141 | 142 | SELECT accountid,status,count(accountid) 143 | FROM activity_group 144 | WHERE `status`!=3 145 | GROUP BY 1 146 | ORDER BY 3 DESC; 147 | 148 | 拼团已经过期的团长中———有交易行为的团长 149 | SELECT DISTINCT(accountid) 150 | FROM da_account_trade 151 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 152 | AND accountid in (SELECT accountid FROM activity_group WHERE `status`=4 GROUP BY 1) 153 | 154 | 过期团长中——邀请yu渠道用户数量 155 | SELECT count(DISTINCT(id)) 156 | FROM da_account 157 | WHERE commandid is not null 158 | AND id in (SELECT accountid FROM activity_group WHERE `status`=4 GROUP BY 1); 159 | 160 | 有交易行为的过期团长中——邀请yu渠道用户数量 161 | 162 | 163 | SELECT count(DISTINCT(id)) 164 | FROM da_account 165 | WHERE commandid IS NOT NULL 166 | AND id IN ( 167 | SELECT DISTINCT(accountid) 168 | FROM da_account_trade 169 | WHERE biztype IN (1, 3) 170 | AND inouttype = 1 171 | AND `status` = 20 172 | AND accountid IN ( 173 | SELECT accountid 174 | FROM activity_group 175 | WHERE `status` = 4 176 | GROUP BY 1 177 | ) 178 | ); 179 | 180 | 181 | 过期团长中有交易行为的308个团长交易额最大的十个: 182 | 183 | SELECT accountid,mobile 184 | FROM da_ds_account_variable_0111 185 | WHERE accountid in (SELECT accountid FROM ( 186 | SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) 187 | FROM da_account_trade 188 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 189 | AND accountid in (SELECT accountid FROM activity_group WHERE `status`=4 GROUP BY 1) 190 | GROUP BY 1 ORDER BY 2 DESC LIMIT 15) aaa) 191 | 192 | 拼团过期的392个团长中,在拼团活动中有交易行为的12个团长: 193 | SELECT accountid,mobile 194 | FROM da_ds_account_variable_0111 195 | WHERE accountid in 196 | (SELECT accountid FROM 197 | (SELECT accountid,sum(amount) 198 | FROM activity_group_detail 199 | WHERE accountid in (SELECT accountid FROM activity_group WHERE `status`=4) AND `status`=1 200 | GROUP BY 1 201 | ORDER BY 2 DESC)aaa); 202 | 203 | 204 | 拼团过期的392个团长中没有交易行为的84个团长中的10个用户: 205 | SELECT accountid,mobile 206 | FROM da_ds_account_variable_0111 207 | WHERE accountid in 208 | (SELECT accountid 209 | FROM activity_group 210 | WHERE `status`=4 AND accountid not in (SELECT accountid 211 | FROM da_account_trade 212 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 213 | AND accountid in (SELECT accountid FROM activity_group WHERE `status`=4 GROUP BY 1) 214 | GROUP BY 1 )) 215 | 216 | 217 | 每个过期团长的团队的用户数 218 | SELECT accountid,mobile,count 219 | FROM 220 | (SELECT accountid,mobile 221 | FROM da_ds_account_variable_0111 222 | WHERE accountid in 223 | (SELECT accountid 224 | FROM activity_group 225 | WHERE `status`=4 AND accountid not in (SELECT accountid 226 | FROM da_account_trade 227 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 228 | AND accountid in (SELECT accountid FROM activity_group WHERE `status`=4 GROUP BY 1) 229 | GROUP BY 1 ))) aaaa 230 | LEFT JOIN 231 | (SELECT a.accountid as aaa,b.count 232 | from 233 | (SELECT accountid,id FROM activity_group WHERE `status`=4) a 234 | JOIN 235 | (SELECT groupid,count(accountid) as count 236 | FROM activity_group_detail 237 | WHERE groupid in (SELECT id FROM activity_group WHERE `status`=4) 238 | GROUP BY 1) b 239 | ON a.id=b.groupid) bbbb 240 | ON aaaa.accountid=bbbb.aaa 241 | GROUP BY 1; 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 【【【【渠道分析】】】】 254 | #渠道注册人数 255 | SELECT channel,count(id) as count 256 | FROM youyu_account 257 | WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27' 258 | GROUP BY channel 259 | ORDER BY count DESC; 260 | #渠道绑卡人数 261 | SELECT channel,count(channel) 262 | FROM youyu_account_trade 263 | WHERE DATE_FORMAT(paysuccesstime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27' AND `status` = 20 AND inouttype = 1 and biztype=4 264 | and accountid in (SELECT id FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27' ) 265 | GROUP BY channel; 266 | #渠道交易人数 267 | SELECT channel,count(DISTINCT(accountid)) 268 | FROM youyu_account_trade 269 | WHERE DATE_FORMAT(paysuccesstime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 270 | AND channel IN (SELECT channel FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27') 271 | AND accountid in (SELECT id FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27') 272 | GROUP BY channel; 273 | 【汇总】 274 | SELECT a.channel,a.count(id),b.count(channel) 275 | FROM 276 | (SELECT channel,count(id) as count 277 | FROM youyu_account 278 | WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27' 279 | GROUP BY channel)a 280 | LEFT JOIN 281 | (SELECT channel,count(channel),count(DISTINCT(accountid)) 282 | FROM youyu_account_trade 283 | WHERE DATE_FORMAT(paysuccesstime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 284 | AND channel IN (SELECT channel FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27') 285 | AND accountid in (SELECT id FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27') 286 | GROUP BY channel)b 287 | ON a.channel = b.channel 288 | GROUP BY channel; 289 | 290 | 291 | #各种渠道交易额汇总: 292 | SELECT channel,sum(amount+couponamount+assetamount+bonusamount) as sum 293 | FROM youyu_account_trade 294 | WHERE DATE_FORMAT(paysuccesstime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-26' AND `status` = 20 AND biztype in (1,3) AND inouttype=1 295 | AND channel IN (SELECT DISTINCT(channel) FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27') 296 | AND accountid in (SELECT DISTINCT(id) FROM youyu_account WHERE DATE_FORMAT(registtime,'%Y-%m-%d') BETWEEN '2015-11-20' AND '2015-11-27') 297 | GROUP BY channel 298 | ORDER BY sum DESC; 299 | -------------------------------------------------------------------------------- /新老用户交易区分: -------------------------------------------------------------------------------- 1 | #【新用户】--单日新用户交易人数,交易笔数,交易金额,平均交易金额 2 | SELECT date(createtime), 3 | count(DISTINCT(accountid))as 用户数, 4 | count(accountid)as 交易次数, 5 | sum(amount+assetamount+bonusamount+couponamount)as 交易额, 6 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) as 客均指 7 | FROM da_account_trade 8 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 AND date(createtime)='2016-01-05' 9 | AND accountid NOT IN (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 10 | and date(createtime) < '2016-01-05'); 11 | 12 | 13 | #【老用户】--单日老用户交易人数,交易笔数,交易金额,平均交易金额 14 | SELECT date(createtime), 15 | count(DISTINCT(accountid))as 用户数, 16 | count(accountid)as 交易次数, 17 | sum(amount+assetamount+bonusamount+couponamount)as 交易额, 18 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) as 客均指 19 | FROM da_account_trade 20 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 AND date(createtime)='2016-01-05' AND accountid IN 21 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 22 | and date(createtime) < '2016-01-05'); 23 | 24 | 25 | #【首次交易不同产品人数、笔数——新用户】 26 | SELECT left(b.itemtitle,3),a.renshu as 人数,a.bishu as 笔数 27 | FROM 28 | (SELECT itemid,accountid,count(DISTINCT(accountid))as renshu,count(accountid)as bishu 29 | FROM da_account_trade 30 | WHERE biztype in (1,3) AND inouttype = 1 and `status`=20 AND date(createtime)='2016-01-05' AND accountid not in 31 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 32 | and date(createtime) < '2016-01-05') 33 | GROUP BY 1) a 34 | LEFT JOIN 35 | (SELECT * FROM selfitem) b 36 | on a.itemid = b.id 37 | GROUP BY 1; 38 | 39 | 40 | #【首次交易不同产品人数——老用户】 41 | SELECT left(b.itemtitle,3),a.renshu,a.bishu 42 | FROM 43 | (SELECT itemid,accountid,count(DISTINCT(accountid))as renshu,count(accountid)as bishu FROM da_account_trade 44 | WHERE biztype in (1,3) AND inouttype = 1 and `status`=20 AND date(createtime)='2016-01-05' AND accountid in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 45 | and date(createtime) < '2016-01-05') 46 | GROUP BY 1) a 47 | LEFT JOIN 48 | (SELECT * FROM selfitem) b 49 | on a.itemid = b.id 50 | GROUP BY 1; 51 | -------------------------------------------------------------------------------- /日报: -------------------------------------------------------------------------------- 1 | 【一、每日概况】 2 | #1、单日注册人数 3 | SELECT date(registtime),count(id) FROM da_account WHERE date(registtime)>'2016-01-20' 4 | GROUP BY date(registtime); 5 | #单日首次交易人数查询 6 | -- 当天总的交易人数 7 | -- SELECT count(DISTINCT(accountid)) 8 | -- FROM da_account_trade 9 | -- WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2015-12-29'; 10 | -- 当天首次交易人数 11 | -- SELECT count(DISTINCT(accountid)) 12 | -- FROM da_account_trade 13 | -- WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2015-12-29' 14 | -- AND accountid NOT IN (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) 15 | -- AND inouttype = 1 AND `status` = 20 and date(createtime) < '2015-12-29'); 16 | #2、当天首次交易的人数 17 | SELECT date(createtime),count(DISTINCT(accountid)) 18 | FROM da_account_trade 19 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2015-12-28' 20 | AND accountid not in 21 | (SELECT accountid 22 | FROM da_account_trade 23 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2015-12-28' GROUP BY 1) 24 | GROUP BY 1; 25 | 26 | 绑卡用户计算 27 | SELECT date(createtime),count(DISTINCT(accountid)) 28 | FROM da_account_trade 29 | WHERE biztype=4 and inouttype=1 AND `status`=20 30 | GROUP BY 1 31 | 32 | SELECT date(registtime),count(DISTINCT(id)) 33 | FROM ds_account 34 | WHERE realname is not null 35 | GROUP BY 1 36 | #3、【每天绑卡用户计算】--交易表+鉴权表 37 | SELECT t1,count1,count2,sum(count1+count2) 38 | from 39 | (SELECT date(createtime) as t1,count(DISTINCT(accountid)) as count1 FROM da_account_trade WHERE biztype=4 AND inouttype=1 AND `status`=20 GROUP BY 1) a 40 | RIGHT JOIN 41 | (SELECT date(createtime) as t2,count(DISTINCT(accountid)) as count2 FROM account_independent_authentication WHERE `status`=20 GROUP BY 1) b 42 | ON a.t1=b.t2 43 | GROUP BY 1 44 | HAVING t1>'2015-01-20'; 45 | #【4】单日交易笔数 46 | SELECT date(createtime),count(accountid) 47 | FROM da_account_trade 48 | WHERE date(createtime)>'2016-01-20' AND biztype in (1,3) AND `status` = 20 AND inouttype =1 49 | GROUP BY 1; 50 | 51 | 52 | 5、【各类产品每日交易总额】 53 | SELECT left(b.itemtitle,3),sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) 54 | FROM 55 | (SELECT * FROM da_account_trade 56 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2016-01-26') a 57 | LEFT JOIN 58 | (SELECT * FROM selfitem) b 59 | ON a.itemid = b.id 60 | GROUP BY 1; 61 | 62 | 6、【点点宝】 63 | #点点宝每日交易额(资金流入) 64 | SELECT date(createtime),sum(amount+couponamount+bonusamount+assetamount) 65 | FROM da_account_trade 66 | WHERE biztype=3 AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-01-15' 67 | GROUP BY 1; 68 | #点点宝每日赎回总额(资金流出) 69 | SELECT date(createtime),sum(amount+couponamount+bonusamount+assetamount) 70 | FROM da_account_trade 71 | WHERE biztype=3 AND inouttype=2 AND `status`=20 AND date(createtime)>'2016-01-15' 72 | GROUP BY 1; 73 | #点点宝每日收益 74 | SELECT date(incomedate),sum(income) 75 | FROM account_ddb_income 76 | WHERE date(incomedate)>'2016-01-15' 77 | GROUP BY 1; 78 | 79 | #【5】当日交易额 80 | SELECT date(createtime),sum(amount+assetamount+couponamount+bonusamount)as sum 81 | FROM da_account_trade 82 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 83 | AND DATE_FORMAT(createtime,'%Y-%m-%d')>'2016-01-15' 84 | GROUP BY 1; 85 | #总提现金额 86 | SELECT date(createtime),sum(amount+couponamount+bonusamount+assetamount) 87 | FROM da_account_trade 88 | WHERE biztype=4 AND inouttype=2 AND `status` in (5,6,20) AND date(createtime)>'2016-01-15' 89 | GROUP BY 1; 90 | 91 | #单天四种交易资金计算: 92 | SELECT date(createtime),sum(amount),sum(assetamount),sum(bonusamount),sum(couponamount) 93 | FROM da_account_trade 94 | WHERE biztype in(1,3) AND `status`=20 AND inouttype=1 95 | AND date(createtime)='2016-01-26'; 96 | #产品分布 97 | SELECT b.annualrate,count(DISTINCT(a.itemid))as count,sum(a.amount+a.bonusamount+a.couponamount+a.assetamount) as sum 98 | FROM 99 | (SELECT * FROM da_account_trade WHERE DATE_FORMAT(createtime,'%Y-%m-%d')='2016-01-26' 100 | AND biztype in (1,3) AND inouttype = 1 AND `status`=20) a 101 | LEFT JOIN 102 | (SELECT * FROM selfitem) b 103 | ON a.itemid = b.id 104 | GROUP BY 1; 105 | 106 | 107 | 【二、渠道明细】 108 | SELECT xxx.channel,aaa.count,bbb.count,ccc.count,ddd.sum,eee.sum,fff.sum,ggg.count,hhh.count,iii.sum 109 | FROM 110 | (SELECT channel 111 | from da_account 112 | GROUP BY 1) xxx 113 | LEFT JOIN 114 | (#1、遍历注册渠道的注册人数 115 | SELECT channel,count(id) as count 116 | FROM da_account 117 | WHERE date(registtime)='2016-01-26' 118 | GROUP BY 1) aaa 119 | ON xxx.channel=aaa.channel 120 | LEFT JOIN 121 | (#2、遍历注册渠道的绑卡人数 122 | SELECT b.channel as channel,count(accountid) as count 123 | FROM 124 | (SELECT accountid 125 | FROM da_account_trade 126 | WHERE biztype=4 AND inouttype=1 AND `status`=20 127 | AND date(createtime)='2016-01-26') a 128 | LEFT JOIN 129 | (SELECT * FROM da_account) b 130 | ON b.id = a.accountid 131 | GROUP BY 1) bbb 132 | ON xxx.channel=bbb.channel 133 | LEFT JOIN 134 | (#3、遍历注册渠道的交易人数 135 | SELECT b.channel as channel,count(accountid) as count 136 | FROM 137 | (SELECT DISTINCT(accountid) 138 | FROM da_account_trade 139 | WHERE biztype in (1,3) AND inouttype=1 and `status`=20 AND date(createtime)='2016-01-26' 140 | AND accountid not in (SELECT accountid 141 | FROM da_account_trade 142 | WHERE biztype in (1,3) AND inouttype=1 and `status`=20 AND date(createtime)<'2016-01-26')) a 143 | LEFT JOIN 144 | (SELECT * FROM da_account) b 145 | ON b.id = a.accountid 146 | GROUP BY 1) ccc 147 | ON xxx.channel=ccc.channel 148 | LEFT JOIN 149 | (#4、新用户首次交易金额: 150 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 151 | FROM 152 | (SELECT accountid,amount,assetamount,bonusamount,couponamount 153 | FROM da_account_trade 154 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 155 | AND date(createtime)='2016-01-26' 156 | AND accountid not in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-26') 157 | GROUP BY 1) a 158 | LEFT JOIN 159 | (SELECT id,channel FROM da_account) b 160 | ON a.accountid = b.id 161 | GROUP BY 1) ddd 162 | ON xxx.channel=ddd.channel 163 | LEFT JOIN 164 | (#5、新用户交易额 165 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 166 | FROM 167 | (SELECT * FROM da_account_trade 168 | WHERE date(createtime)='2016-01-26' AND biztype in (1,3) AND inouttype=1 AND `status`=20 169 | AND accountid not in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-26')) a 170 | LEFT JOIN 171 | (SELECT id,channel FROM da_account) b 172 | ON a.accountid = b.id 173 | GROUP BY 1) eee 174 | ON xxx.channel=eee.channel 175 | LEFT JOIN 176 | (#6、新老用户交易额 177 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 178 | FROM 179 | (SELECT * 180 | FROM da_account_trade 181 | WHERE date(createtime)='2016-01-26' AND biztype in (1,3) AND inouttype=1 AND `status`=20) a 182 | LEFT JOIN 183 | (SELECT id,channel FROM da_account) b 184 | ON a.accountid = b.id 185 | GROUP BY 1) fff 186 | ON xxx.channel=fff.channel 187 | LEFT JOIN 188 | (-- 【渠道累计】 189 | #7、渠道累计注册人数 190 | SELECT channel,count(id) as count 191 | FROM da_account 192 | WHERE date(registtime) < '2016-01-29' 193 | GROUP BY 1) ggg 194 | ON xxx.channel=ggg.channel 195 | LEFT JOIN 196 | (#8、渠道累计交易人数 197 | SELECT b.channel as channel,count(*) as count 198 | FROM 199 | (SELECT accountid,amount,assetamount,bonusamount,couponamount FROM da_account_trade 200 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-29' GROUP BY 1 ) a 201 | LEFT JOIN 202 | (SELECT id,channel FROM da_account) b 203 | ON a.accountid = b.id 204 | GROUP BY 1) hhh 205 | ON xxx.channel=hhh.channel 206 | LEFT JOIN 207 | (#9、渠道累计交易金额 208 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 209 | FROM 210 | (SELECT * 211 | FROM da_account_trade 212 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-29') a 213 | LEFT JOIN 214 | (SELECT id,channel FROM da_account) b 215 | ON a.accountid = b.id 216 | GROUP BY 1) iii 217 | ON xxx.channel=iii.channel 218 | WHERE xxx.channel is not null 219 | GROUP BY 1; 220 | 221 | 【三、邀请与渠道】 222 | #【注册用户】 223 | SELECT a.dda,count1,count2,count1/(count1+count2),count2/(count1+count2),count3,count4,count3/(count3+count4),count4/(count4+count3) 224 | from 225 | (#1、【每日渠道注册用户数】 226 | SELECT date(registtime) dda,count(id) count1 227 | FROM da_account 228 | WHERE date(registtime)>'2016-01-10' AND commandid is null 229 | GROUP BY 1) a 230 | JOIN 231 | (#2、【每日邀请注册用户总数】 232 | SELECT date(registtime) dda,count(id)as count2 233 | FROM da_account 234 | WHERE date(registtime)>'2016-01-10' AND commandid is not null 235 | GROUP BY 1) b 236 | ON a.dda=b.dda 237 | JOIN 238 | (#【交易用户】 239 | #3、当日新增用户之中来自渠道途径的用户数: 240 | SELECT date(createtime) as dda,count(DISTINCT(accountid)) as count3 241 | FROM da_account_trade 242 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m-%d')='2016-01-26' 243 | AND accountid not in (SELECT accountid FROM da_account_trade 244 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-26') 245 | AND accountid in (SELECT id FROM da_account WHERE commandid is null)) c 246 | ON a.dda=c.dda 247 | JOIN 248 | (#4、当日新增用户之中来自邀请途径的用户数: 249 | SELECT date(createtime) as dda,count(DISTINCT(accountid)) as count4 250 | FROM da_account_trade 251 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m-%d')='2016-01-26' 252 | AND accountid not in (SELECT accountid FROM da_account_trade 253 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-26') 254 | AND accountid in (SELECT id FROM da_account WHERE commandid is not null)) d 255 | ON a.dda=d.dda; 256 | 257 | 258 | 【四、新老用户交易汇总】 259 | #【新用户】--单日新用户交易人数,交易笔数,交易金额,平均交易金额 260 | SELECT date(paysuccesstime), 261 | count(DISTINCT(accountid))as 用户数, 262 | count(accountid)as 交易次数, 263 | sum(amount+assetamount+bonusamount+couponamount)as 交易额, 264 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) as 客均指 265 | FROM da_account_trade 266 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 AND date(createtime)='2016-01-26' 267 | AND accountid NOT IN (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 268 | and date(createtime)<'2016-01-26'); 269 | #【老用户】--单日老用户交易人数,交易笔数,交易金额,平均交易金额 270 | SELECT date(paysuccesstime), 271 | count(DISTINCT(accountid))as 用户数, 272 | count(accountid)as 交易次数, 273 | sum(amount+assetamount+bonusamount+couponamount)as 交易额, 274 | sum(amount+assetamount+bonusamount+couponamount)/count(DISTINCT(accountid)) as 客均指 275 | FROM da_account_trade 276 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 AND date(createtime)='2016-01-26' AND accountid IN 277 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 278 | and date(createtime)<'2016-01-26'); 279 | 280 | #【首次交易不同产品人数——新用户】 281 | SELECT left(b.itemtitle,3),a.renshu,a.bishu 282 | FROM 283 | (SELECT itemid,accountid,count(DISTINCT(accountid))as renshu,count(accountid)as bishu 284 | FROM da_account_trade 285 | WHERE biztype in (1,3) AND inouttype = 1 and `status`=20 AND date(createtime)='2016-01-26' AND accountid not in 286 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 287 | and date(createtime) < '2016-01-26') 288 | GROUP BY 1) a 289 | LEFT JOIN 290 | (SELECT * FROM selfitem) b 291 | on a.itemid = b.id 292 | GROUP BY 1; 293 | #【首次交易不同产品人数——老用户】 294 | SELECT left(b.itemtitle,3),a.renshu,a.bishu 295 | FROM 296 | (SELECT itemid,accountid,count(DISTINCT(accountid))as renshu,count(accountid)as bishu 297 | FROM da_account_trade 298 | WHERE biztype in (1,3) AND inouttype = 1 and `status`=20 AND date(createtime)='2016-01-26' AND accountid in 299 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 300 | and date(createtime) < '2016-01-26') 301 | GROUP BY 1) a 302 | LEFT JOIN 303 | (SELECT * FROM selfitem) b 304 | on a.itemid = b.id 305 | GROUP BY 1; 306 | 307 | 308 | 【五、账户余额】 309 | SELECT a.da,a.sum,b.sum,c.count,0,sum(a.sum+b.sum+c.count) as total1, 310 | d.sum,e.sum,sum(d.sum+e.sum) as total2, 311 | sum(a.sum+b.sum+c.count)-sum(d.sum+e.sum), 312 | d.sum/sum(d.sum+e.sum) as per1,e.sum/sum(d.sum+e.sum) as per2 313 | FROM 314 | (#1、点点宝赎回 315 | SELECT date(createtime) as da,sum(amount+assetamount+bonusamount+couponamount) as sum FROM da_account_trade 316 | WHERE biztype=3 AND inouttype=2 AND `status`=20 AND date(createtime)>'2016-01-10' 317 | GROUP BY 1 ) a 318 | LEFT JOIN 319 | (#2、优选理财回款 320 | #此处的优选理财回款不用减去收益 321 | SELECT date(createtime) as da,sum(amount) as sum FROM account_inout 322 | WHERE biztype=1 AND inouttype=2 AND date(createtime)>'2016-01-10' 323 | GROUP BY 1 ) b 324 | ON a.da=b.da 325 | LEFT JOIN 326 | (#3、绑卡充值人数 327 | SELECT date(createtime) as da,count(*) as count FROM da_account_trade 328 | WHERE biztype=4 AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-01-10' 329 | GROUP BY 1 ) c 330 | ON a.da=c.da 331 | LEFT JOIN 332 | (#4、余额再次投资 333 | SELECT date(createtime) as da,sum(assetamount) as sum FROM da_account_trade 334 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-01-10' 335 | GROUP BY 1 ) d 336 | ON a.da=d.da 337 | LEFT JOIN 338 | (#5、提现 339 | SELECT date(createtime) as da,sum(amount+assetamount+bonusamount+couponamount) as sum 340 | FROM da_account_trade 341 | WHERE biztype=4 and inouttype=2 and `status` in (5,6,20) AND date(createtime)>'2016-01-10' 342 | GROUP BY 1 ) e 343 | ON a.da=e.da 344 | GROUP BY 1; 345 | 346 | 347 | 【六、 签到统计】 348 | SELECT date(createtime),count(*) 349 | FROM score_gain_stream 350 | WHERE `status`=1 AND date(createtime)>'2016-01-20' 351 | GROUP BY 1; 352 | -------------------------------------------------------------------------------- /日报-渠道明: -------------------------------------------------------------------------------- 1 | SELECT xxx.channel,aaa.count,bbb.count,ccc.count,ddd.sum,eee.sum,fff.sum,ggg.count,hhh.count,iii.sum 2 | FROM 3 | (SELECT channel 4 | from da_account 5 | GROUP BY 1) xxx 6 | LEFT JOIN 7 | (#1、遍历注册渠道的注册人数 8 | SELECT channel,count(id) as count 9 | FROM da_account 10 | WHERE date(registtime)='2016-01-11' 11 | GROUP BY 1) aaa 12 | ON xxx.channel=aaa.channel 13 | LEFT JOIN 14 | (#2、遍历注册渠道的绑卡人数 15 | SELECT b.channel as channel,count(accountid) as count 16 | FROM 17 | (SELECT accountid 18 | FROM da_account_trade 19 | WHERE biztype=4 AND inouttype=1 AND `status`=20 20 | AND date(createtime)='2016-01-11') a 21 | LEFT JOIN 22 | (SELECT * FROM da_account) b 23 | ON b.id = a.accountid 24 | GROUP BY 1) bbb 25 | ON xxx.channel=bbb.channel 26 | LEFT JOIN 27 | (#3、遍历注册渠道的交易人数 28 | SELECT b.channel as channel,count(accountid) as count 29 | FROM 30 | (SELECT DISTINCT(accountid) 31 | FROM da_account_trade 32 | WHERE biztype in (1,3) AND inouttype=1 and `status`=20 AND date(createtime)='2016-01-11' 33 | AND accountid not in (SELECT accountid 34 | FROM da_account_trade 35 | WHERE biztype in (1,3) AND inouttype=1 and `status`=20 AND date(createtime)<'2016-01-11')) a 36 | LEFT JOIN 37 | (SELECT * FROM da_account) b 38 | ON b.id = a.accountid 39 | GROUP BY 1) ccc 40 | ON xxx.channel=ccc.channel 41 | LEFT JOIN 42 | (#4、新用户首次交易金额: 43 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 44 | FROM 45 | (SELECT accountid,amount,assetamount,bonusamount,couponamount 46 | FROM da_account_trade 47 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 48 | AND date(createtime)='2016-01-11' 49 | AND accountid not in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-11') 50 | GROUP BY 1) a 51 | LEFT JOIN 52 | (SELECT id,channel FROM da_account) b 53 | ON a.accountid = b.id 54 | GROUP BY 1) ddd 55 | ON xxx.channel=ddd.channel 56 | LEFT JOIN 57 | (#5、新用户交易额 58 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 59 | FROM 60 | (SELECT * FROM da_account_trade 61 | WHERE date(createtime)='2016-01-11' AND biztype in (1,3) AND inouttype=1 AND `status`=20 62 | AND accountid not in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-11')) a 63 | LEFT JOIN 64 | (SELECT id,channel FROM da_account) b 65 | ON a.accountid = b.id 66 | GROUP BY 1) eee 67 | ON xxx.channel=eee.channel 68 | LEFT JOIN 69 | (#6、新老用户交易额 70 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 71 | FROM 72 | (SELECT * 73 | FROM da_account_trade 74 | WHERE date(createtime)='2016-01-11' AND biztype in (1,3) AND inouttype=1 AND `status`=20) a 75 | LEFT JOIN 76 | (SELECT id,channel FROM da_account) b 77 | ON a.accountid = b.id 78 | GROUP BY 1) fff 79 | ON xxx.channel=fff.channel 80 | LEFT JOIN 81 | (-- 【渠道累计】 82 | #7、渠道累计注册人数 83 | SELECT channel,count(id) as count 84 | FROM da_account 85 | WHERE date(registtime) < '2016-01-12' 86 | GROUP BY 1) ggg 87 | ON xxx.channel=ggg.channel 88 | LEFT JOIN 89 | (#8、渠道累计交易人数 90 | SELECT b.channel as channel,count(*) as count 91 | FROM 92 | (SELECT accountid,amount,assetamount,bonusamount,couponamount FROM da_account_trade 93 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-12' GROUP BY 1 ) a 94 | LEFT JOIN 95 | (SELECT id,channel FROM da_account) b 96 | ON a.accountid = b.id 97 | GROUP BY 1) hhh 98 | ON xxx.channel=hhh.channel 99 | LEFT JOIN 100 | (#9、渠道累计交易金额 101 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 102 | FROM 103 | (SELECT * 104 | FROM da_account_trade 105 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-12') a 106 | LEFT JOIN 107 | (SELECT id,channel FROM da_account) b 108 | ON a.accountid = b.id 109 | GROUP BY 1) iii 110 | ON xxx.channel=iii.channel 111 | GROUP BY 1; 112 | -------------------------------------------------------------------------------- /月报: -------------------------------------------------------------------------------- 1 | 2016-05-06 :4月份新用户现金券消耗情况 2 | SELECT channel,count(a.accountid),sum(sum) 3 | FROM 4 | (SELECT accountid 5 | FROM da_account_trade 6 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime) between '2016-03-01' AND '2016-03-31' 7 | AND accountid not in 8 | (SELECT accountid from da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-03-01' GROUP BY 1) 9 | GROUP BY 1 ) a 10 | LEFT JOIN 11 | (SELECT id,channel from da_account ) b 12 | ON a.accountid=b.id 13 | LEFT JOIN 14 | (SELECT accountid,sum(usemoney) as sum 15 | FROM account_coupons_used 16 | WHERE date(createtime) BETWEEN '2016-03-01' AND '2016-03-31' AND date(usetime) BETWEEN '2016-03-01' AND '2016-03-31' 17 | GROUP BY 1)c 18 | ON a.accountid=c.accountid 19 | GROUP BY 1 20 | ORDER BY 3 DESC; 21 | 22 | 23 | 24 | 25 | 2016-05-09 :四月份新用户的交易情况: 26 | SELECT channel,count(accountid),sum(sum) 27 | FROM 28 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 29 | FROM da_account_trade 30 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime) between '2016-03-01' AND '2016-03-31' 31 | AND accountid not in 32 | (SELECT accountid 33 | from da_account_trade 34 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-04-01' 35 | GROUP BY 1) 36 | GROUP BY 1 ) a 37 | LEFT JOIN 38 | (SELECT id,channel from da_account ) b 39 | ON a.accountid=b.id 40 | GROUP BY 1 41 | ORDER BY 3 DESC 42 | 43 | SELECT * 44 | FROM da_account 45 | where channel = 'null' AND date(registtime)>'2016-04-30' 46 | -- where channel = 'null' AND date(registtime) BETWEEN '2016-03-01' AND '2016-03-31' 47 | 48 | 49 | 【新增用户】 50 | #11月:注册量 51 | select count(id) from account where date_format(registtime,'%Y-%m')='2016-06'; 52 | 53 | -- 12月新增绑卡(1) 54 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(DISTINCT(accountid)) 55 | FROM account_independent_authentication 56 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2016-06' 57 | AND accountid in (select id from account where date_format(registtime,'%Y-%m')='2016-06' ); 58 | 59 | -- -- 12月新增绑卡(2) 60 | -- SELECT DATE_FORMAT(createtime,'%Y-%m'),count(DISTINCT(accountid)) 61 | -- FROM da_account_trade 62 | -- WHERE biztype=4 AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-05' 63 | -- AND accountid in (select id from da_account where date_format(registtime,'%Y-%m')='2016-05'); 64 | 65 | -- X月新增交易 66 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(DISTINCT(accountid)) 67 | FROM account_trade 68 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2016-06' AND biztype in (1,3) AND inouttype=1 AND `status`=20 69 | AND accountid in (select id from account where date_format(registtime,'%Y-%m')='2016-06' ); 70 | 71 | 72 | 73 | #12月:总绑卡量 74 | SELECT a.dda,sum(countjianquan+countjiaoyi) 75 | FROM 76 | (SELECT DATE_FORMAT(createtime,'%Y-%m') as dda,count(DISTINCT(accountid)) as countjianquan 77 | FROM account_independent_authentication 78 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2016-06' 79 | GROUP BY 1 ) a #每个月鉴权表里面总的绑卡用户数 80 | LEFT JOIN 81 | (SELECT DATE_FORMAT(createtime,'%Y-%m') as dda,count(DISTINCT(accountid)) as countjiaoyi 82 | FROM account_trade 83 | WHERE biztype=4 AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-06' 84 | GROUP BY 1) b #交易表里面每个月总的绑卡用户数 85 | ON a.dda=b.dda 86 | GROUP BY 1 87 | ORDER BY 1 DESC; 88 | 89 | #12月:总交易量 90 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(DISTINCT(accountid)) 91 | FROM account_trade 92 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')>'2015-08' 93 | GROUP BY 1 94 | ORDER BY 1 DESC; 95 | 96 | 97 | 【新用户】 98 | SELECT count(DISTINCT(accountid)),sum(amount+assetamount+bonusamount+couponamount) 99 | FROM account_trade 100 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-06' 101 | AND accountid not in 102 | (SELECT accountid 103 | FROM account_trade 104 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')<'2016-06'); 105 | 106 | #交易次数 107 | SELECT count,count(accountid),sum(sum) 108 | FROM 109 | (SELECT accountid,count(accountid) as count,sum(amount+assetamount+bonusamount+couponamount) as sum 110 | FROM account_trade 111 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-06' 112 | AND accountid not in 113 | (SELECT accountid FROM account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')<'2016-06') 114 | GROUP BY accountid) xxoo 115 | GROUP BY 1; 116 | 117 | 【老用户】 118 | #当月老用户总数 119 | SELECT count(DISTINCT(accountid)),sum(amount+assetamount+bonusamount+couponamount) 120 | FROM account_trade 121 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-06' 122 | AND accountid in 123 | (SELECT accountid FROM account_trade 124 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')<'2016-06' GROUP BY 1); 125 | 126 | 127 | 128 | #某月老用户交易次数=1/2/3/3次以上的: 129 | SELECT count(accountid),sum(sum) 130 | FROM 131 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount)as sum 132 | FROM account_trade 133 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-06' 134 | AND accountid in 135 | (SELECT accountid 136 | FROM account_trade 137 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')<'2015-02' GROUP BY 1) 138 | GROUP BY 1 139 | HAVING count(accountid)>3 )a; 140 | 141 | 142 | 143 | 144 | #老用户注册渠道分布,及其各渠道交易额 145 | SELECT b.channel,count(accountid),sum(sum),round(sum(sum)/count(accountid),2) 146 | from 147 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 148 | FROM account_trade 149 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 150 | AND accountid in (SELECT accountid FROM account_trade WHERE biztype in (1,3) AND inouttype=1 151 | AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')<'2016-06' GROUP BY 1) 152 | AND DATE_FORMAT(createtime,'%Y-%m')='2016-06' 153 | GROUP BY 1)a 154 | LEFT JOIN 155 | (SELECT id,channel FROM account) b 156 | ON a.accountid=b.id 157 | GROUP BY 1 158 | ORDER BY 2 desc 159 | LIMIT 38; 160 | 161 | 162 | 【交易量】 163 | #每月交易总额(资金流入) 164 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+couponamount+bonusamount+assetamount) 165 | FROM account_trade 166 | WHERE biztype in(1,3) AND inouttype=1 AND `status`=20 167 | GROUP BY 1; 168 | #点点宝每月交易额(资金流入) 169 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+couponamount+bonusamount+assetamount) 170 | FROM account_trade 171 | WHERE biztype=3 AND inouttype=1 AND `status`=20 AND date(createtime)>'2015-11-30' 172 | GROUP BY 1; 173 | #定期理财每日交易额(资金流入) 174 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+couponamount+bonusamount+assetamount) 175 | FROM account_trade 176 | WHERE biztype=1 AND inouttype=1 AND `status`=20 AND date(createtime)>'2015-11-30' 177 | GROUP BY 1; 178 | #每日提现总额(资金流出) 179 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+couponamount+bonusamount+assetamount) 180 | FROM account_trade 181 | WHERE biztype=4 AND inouttype=2 AND `status` in (5,6,20) AND DATE_FORMAT(createtime,'%Y-%m')>'2015-10' 182 | GROUP BY 1; 183 | #点点宝每日赎回总额(资金流出) 184 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount+couponamount+bonusamount+assetamount) 185 | FROM account_trade 186 | WHERE biztype=3 AND inouttype=2 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')>'2015-10' 187 | GROUP BY 1; 188 | #定期理财每日回款总额(资金流出) 189 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(amount-profit) 190 | FROM account_inout 191 | WHERE biztype=1 AND inouttype=2 AND DATE_FORMAT(createtime,'%Y-%m')>'2015-10' 192 | GROUP BY 1; 193 | 194 | 195 | 【红包,现金券】12月份 196 | #红包发放 197 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(bonus) 198 | FROM account_bonus 199 | WHERE DATE_FORMAT(createtime,'%Y-%m')>'2015-09' AND inouttype = 1 200 | GROUP BY 1 201 | ORDER BY 1 DESC; 202 | #红包使用 203 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(bonusamount) 204 | FROM account_trade 205 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2016-06' AND biztype in (1,3) AND `status`=20 AND inouttype=1 206 | GROUP BY 1 207 | ORDER BY 1 DESC; 208 | #发放现金券 209 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(money) 210 | FROM account_coupons 211 | WHERE DATE_FORMAT(createtime,'%Y-%m')>'2015-09' 212 | GROUP BY 1 213 | ORDER BY 1 DESC; 214 | #现金券的使用 215 | SELECT DATE_FORMAT(createtime,'%Y-%m'),sum(couponamount) 216 | FROM account_trade 217 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2016-06' AND inouttype = 1 AND `status` = 20 AND biztype in (1,3) 218 | GROUP BY 1 219 | ORDER BY 1 DESC; 220 | 221 | #现金券的过期 222 | SELECT DATE_FORMAT(endtime,'%Y-%m'),sum(money) 223 | FROM account_coupons 224 | WHERE DATE_FORMAT(createtime,'%Y-%m')>'2015-09' and `status`=3 225 | GROUP BY 1; 226 | 227 | 【支付成功率】=支付成功笔数/(成功笔数+失败笔数) 228 | #每月支付成功笔数 229 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(*) 230 | FROM account_trade 231 | WHERE `status`=20 AND biztype in (1,3) AND inouttype=1 AND DATE_FORMAT(createtime,'%Y-%m')>'2015-07' 232 | GROUP BY 1 233 | ORDER BY 1 DESC; 234 | #每月支付失败笔数 235 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(*) 236 | FROM account_trade 237 | WHERE `status`=30 AND biztype in (1,3) AND inouttype=1 AND DATE_FORMAT(createtime,'%Y-%m')>'2015-07' 238 | GROUP BY 1; 239 | 240 | #每日支付成功笔数 241 | SELECT date(createtime),count(*) 242 | FROM account_trade 243 | WHERE `status`=20 AND biztype in (1,3) AND inouttype=1 AND date(createtime)>'2016-05-31' 244 | GROUP BY 1; 245 | 246 | #每日支付的失败笔数 247 | SELECT date(createtime),count(*) 248 | FROM account_trade 249 | WHERE `status`=30 AND biztype in (1,3) AND inouttype=1 AND date(createtime)>'2016-05-31' 250 | GROUP BY 1; 251 | 252 | #账户提现金额 253 | SELECT sum(amount) 254 | FROM account_cashout 255 | WHERE DATE_FORMAT(createtime,'%Y-%m')='2015-11' AND `status`=20 256 | 257 | #单月注册: 258 | SELECT count(id) 259 | FROM account 260 | WHERE DATE_FORMAT(registtime,'%Y-%m')='2016-07'; 261 | 262 | #单月绑卡 263 | SELECT count(DISTINCT accountid) 264 | FROM account_independent_authentication 265 | where `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-07'; 266 | 267 | #单月交易 268 | SELECT count(DISTINCT(accountid)) 269 | FROM account_trade 270 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-07'; 271 | 272 | #新增绑卡 273 | SELECT count(DISTINCT accountid) 274 | FROM account_independent_authentication 275 | where `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-07' 276 | AND accountid in (SELECT id FROM account WHERE DATE_FORMAT(registtime,'%Y-%m')='2016-07'); 277 | 278 | #新增交易 279 | SELECT count(DISTINCT(accountid)) 280 | FROM account_trade 281 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-07' 282 | AND accountid in (SELECT id FROM account WHERE DATE_FORMAT(registtime,'%Y-%m')='2016-07'); 283 | 284 | 每个月每天交易数量 285 | SELECT date(createtime),count(DISTINCT(accountid)) 286 | FROM da_account_trade 287 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)>'2015-09-30' 288 | GROUP BY 1 289 | 290 | #新用户 291 | SELECT accountid,count(accountid) 292 | FROM da_account_trade 293 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2015-08' 294 | GROUP BY 1 295 | 296 | 12月份各渠道注册用户量 297 | SELECT channel,count(id) 298 | FROM da_account 299 | WHERE DATE_FORMAT(registtime,'%Y-%m')='2015-12' 300 | GROUP BY 1 301 | ORDER BY 2 DESC 302 | #1 303 | SELECT count,count(DISTINCT(accountid)),sum(sum) 304 | FROM 305 | (SELECT accountid,count(accountid) as count,sum(amount+assetamount+bonusamount+couponamount) as sum 306 | FROM da_account_trade 307 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2015-12' 308 | AND accountid not in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 309 | AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')<'2015-12') 310 | GROUP BY 1) a 311 | GROUP BY 1; 312 | 313 | #老用户 314 | SELECT count(accountid),count(DISTINCT(accountid)),sum(amount+assetamount+bonusamount+couponamount) 315 | FROM da_account_trade 316 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2015-12' 317 | AND accountid in (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2015-12') 318 | 319 | 320 | 321 | #支付成功率 322 | #每日支付成功笔数 323 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(*) 324 | FROM da_account_trade 325 | WHERE `status`=20 AND biztype in(1,3) AND inouttype=1 326 | GROUP BY 1; 327 | #每日支付的失败笔数 328 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(*) 329 | FROM da_account_trade 330 | WHERE `status`=30 AND biztype in (1,3) AND inouttype=1 331 | GROUP BY 1; 332 | 333 | 【付费推广渠道】 334 | #各渠道统计 335 | SELECT channel,count(id) 336 | FROM da_account 337 | WHERE DATE_FORMAT(registtime,'%Y-%m')='2016-01' 338 | AND channel in ('360','baiducpd','xiaomi','lianxiang','kumi','dandanzuan','xiaoniao', 339 | 'jinritoutiao','jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4', 340 | 'ASO','xiaoniao','360yuansheng','oppo','8868') 341 | GROUP BY 1 342 | ORDER BY 2 DESC; 343 | #各渠道交易额 344 | SELECT b.channel,count(accountid),sum(sum) 345 | FROM 346 | (SELECT accountid,count(accountid) as count,sum(amount+assetamount+bonusamount+couponamount) as sum 347 | FROM da_account_trade 348 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2016-01' 349 | GROUP BY 1) a 350 | RIGHT JOIN 351 | (SELECT id,channel 352 | FROM da_account 353 | WHERE DATE_FORMAT(registtime,'%Y-%m')='2016-01' 354 | AND channel in ('360','baiducpd','xiaomi','lianxiang','kumi','dandanzuan','xiaoniao', 355 | 'jinritoutiao','jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4', 356 | 'ASO','xiaoniao','360yuansheng','oppo','8868')) b 357 | ON a.accountid=b.id 358 | GROUP BY 1; 359 | 360 | 361 | SELECT b.channel,count(a.accountid),sum(a.sum) 362 | FROM 363 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 364 | FROM da_account_trade 365 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND date(createtime)<'2016-01-01' 366 | GROUP BY 1) a 367 | LEFT JOIN 368 | (SELECT id,channel FROM da_account WHERE channel in ('360','baiducpd','xiaomi','lianxiang','kumi','dandanzuan','xiaoniao', 369 | 'jinritoutiao','jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4', 370 | 'ASO','xiaoniao','360yuansheng','oppo','8868')) b 371 | ON a.accountid=b.id 372 | GROUP BY 1; 373 | 【【【各渠道现金券消耗】】】 374 | SELECT b.channel,count(accountid),sum(sum1),sum(sum2) 375 | FROM 376 | (SELECT accountid,count(accountid) as count,sum(bonusamount) sum1,sum(couponamount) sum2 377 | FROM da_account_trade 378 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 379 | AND DATE_FORMAT(createtime,'%Y-%m')='2016-01' 380 | -- AND (couponamount>0 or bonusamount>0) 381 | GROUP BY 1) a 382 | LEFT JOIN 383 | (SELECT id,channel FROM da_account ) b 384 | ON a.accountid=b.id 385 | GROUP BY 1 386 | ORDER BY 3 DESC 387 | LIMIT 10; 388 | 389 | SELECT * FROM da_account WHERE channel is null 390 | 【12月份】 391 | 12月份不在本月注册+在本月交易的用户 392 | 393 | 394 | SELECT count(DISTINCT(accountid)),count(accountid),sum(amount+assetamount+bonusamount+couponamount) 395 | FROM da_account_trade 396 | WHERE biztype in (1,3) and inouttype =1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2015-12' 397 | AND accountid in (SELECT id FROM da_account WHERE DATE_FORMAT(registtime,'%Y-%m')<'2015-12'); 398 | 399 | 400 | #各渠道统计 401 | SELECT channel,count(id) 402 | FROM da_account 403 | WHERE DATE_FORMAT(registtime,'%Y-%m')='2015-12' 404 | AND channel in ('360','baiducpd','lianxiang','jinritoutiao','xiaomi', 405 | 'jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4','kumi','dianju','dandanzuan','xiaoniao') 406 | GROUP BY 1 407 | ORDER BY 2 DESC; 408 | 409 | #当月交易人数,交易额 410 | SELECT b.channel,count(accountid),sum(sum) 411 | FROM 412 | (SELECT accountid,count(accountid) as count,sum(amount+assetamount+bonusamount+couponamount) as sum 413 | FROM da_account_trade 414 | where biztype in (1,3) AND inouttype=1 AND `status`=20 AND DATE_FORMAT(createtime,'%Y-%m')='2015-12' 415 | GROUP BY 1 416 | HAVING count>2) a 417 | LEFT JOIN 418 | (SELECT id,channel FROM da_account WHERE channel in ('360','baiducpd','lianxiang','jinritoutiao','xiaomi', 419 | 'jinritoutiao1','jinritoutiao2','jinritoutiao3','jinritoutiao4','kumi','dianju','dandanzuan','xiaoniao')) b 420 | ON a.accountid=b.id 421 | GROUP BY 1 422 | -------------------------------------------------------------------------------- /每日完成情况: -------------------------------------------------------------------------------- 1 | #【1】单日注册量 2 | SELECT date(registtime),count(id) 3 | FROM da_account WHERE date(registtime)>'2015-12-30' 4 | GROUP BY date(registtime); 5 | #【2】单日注册用户中交易人数 6 | SELECT date(tt),count(DISTINCT(aa)) 7 | FROM 8 | (SELECT a.accountid as aa,a.createtime as tt 9 | from 10 | (SELECT accountid,createtime FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20) a 11 | JOIN 12 | (SELECT id,registtime FROM da_account) b 13 | ON a.accountid=b.id AND date(a.createtime)=date(b.registtime) 14 | HAVING a.createtime>'2015-12-30') mm 15 | GROUP BY 1; 16 | 17 | #【3】当日交易额 18 | SELECT date(createtime),sum(amount+assetamount+couponamount+bonusamount)as sum 19 | FROM da_account_trade 20 | WHERE biztype in (1,3) AND inouttype = 1 AND `status` = 20 21 | AND DATE_FORMAT(createtime ,'%Y-%m-%d')>'2015-12-30' 22 | GROUP BY 1; 23 | #单日总计 24 | 按月计算:注册量 25 | SELECT DATE_FORMAT(registtime,'%Y-%m'),count(id) 26 | FROM da_account 27 | WHERE DATE_FORMAT(registtime,'%Y-%m')>'2015-07' 28 | GROUP BY 1; 29 | 按月计算:绑卡量 30 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(DISTINCT(accountid)) 31 | FROM da_account_trade 32 | WHERE DATE_FORMAT(createtime,'%Y-%m')>'2015-07' AND biztype=4 and inouttype=1 AND `status`=20 33 | GROUP BY 1; 34 | 按月计算:交易量 35 | SELECT DATE_FORMAT(createtime,'%Y-%m'),count(DISTINCT(accountid)) 36 | FROM da_account_trade 37 | WHERE DATE_FORMAT(createtime,'%Y-%m')>'2015-07' AND biztype in(1,3) and inouttype=1 AND `status`=20 38 | GROUP BY 1; 39 | 40 | 41 | -------------------------------------------------------------------------------- /每日用户留存: -------------------------------------------------------------------------------- 1 | -- 每日注册用户留存分布: 2 | SELECT dda, 3 | count(id) as count, 4 | count(b.accountid) as count0, 5 | count(c.accountid) as count1, 6 | count(d.accountid) as count7, 7 | count(e.accountid) as count15, 8 | count(f.accountid) as count30, 9 | count(g.accountid) as count60, 10 | count(h.accountid) as count90 11 | FROM 12 | (SELECT id,date(registtime) as dda FROM account WHERE date(registtime)>'2016-5-02' GROUP BY 1,2 ) a 13 | LEFT JOIN 14 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 15 | UNION 16 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) b 17 | ON a.id=b.accountid AND a.dda=date(date_sub(b.ddaa,interval 0 day)) 18 | LEFT JOIN 19 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 20 | UNION 21 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) c 22 | ON a.id=c.accountid AND a.dda=date(date_sub(c.ddaa,interval 1 day)) 23 | LEFT JOIN 24 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 25 | UNION 26 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) d 27 | ON a.id=d.accountid AND a.dda=date(date_sub(d.ddaa,interval 7 day)) 28 | LEFT JOIN 29 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 30 | UNION 31 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) e 32 | ON a.id=e.accountid AND a.dda=date(date_sub(e.ddaa,interval 15 day)) 33 | LEFT JOIN 34 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 35 | UNION 36 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) f 37 | ON a.id=f.accountid AND a.dda=date(date_sub(f.ddaa,interval 30 day)) 38 | LEFT JOIN 39 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 40 | UNION 41 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) g 42 | ON a.id=g.accountid AND a.dda=date(date_sub(g.ddaa,interval 60 day)) 43 | LEFT JOIN 44 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 45 | UNION 46 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) h 47 | ON a.id=h.accountid AND a.dda=date(date_sub(h.ddaa,interval 90 day)) 48 | GROUP BY 1 ; 49 | 50 | 51 | -- 每日交易用户留存统计: 52 | SELECT dda, 53 | count(a.accountid) as count, 54 | count(b.accountid) as count0, #当日留存 55 | count(c.accountid) as count1, #次日留存 56 | count(d.accountid) as count7, #7日留存 57 | count(e.accountid) as count15, #15日留存 58 | count(f.accountid) as count30, #30 日留存 59 | count(g.accountid) as count60, #60日留存 60 | count(h.accountid) as count90 #90日留存 61 | FROM 62 | (SELECT accountid,date(createtime) as dda 63 | FROM account_trade 64 | WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND date(createtime)>'2016-05-02' 65 | GROUP BY 1,2 ) a 66 | LEFT JOIN 67 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 68 | UNION 69 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) b 70 | ON a.accountid=b.accountid AND a.dda=date(date_sub(b.ddaa,interval 0 day)) #单日访问用户 71 | LEFT JOIN 72 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 73 | UNION 74 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) c 75 | ON a.accountid=c.accountid AND a.dda=date(date_sub(c.ddaa,interval 1 day)) #次日访问用户统计 76 | LEFT JOIN 77 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 78 | UNION 79 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) d 80 | ON a.accountid=d.accountid AND a.dda=date(date_sub(d.ddaa,interval 7 day)) #7日访问用户统计 81 | LEFT JOIN 82 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 83 | UNION 84 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) e 85 | ON a.accountid=e.accountid AND a.dda=date(date_sub(e.ddaa,interval 15 day)) #15日访问用户统计 86 | LEFT JOIN 87 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 88 | UNION 89 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) f 90 | ON a.accountid=f.accountid AND a.dda=date(date_sub(f.ddaa,interval 30 day)) #30日访问用户统计 91 | LEFT JOIN 92 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 93 | UNION 94 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) g 95 | ON a.accountid=g.accountid AND a.dda=date(date_sub(g.ddaa,interval 60 day)) #60日访问头用户统计 96 | LEFT JOIN 97 | (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 98 | UNION 99 | SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) h 100 | ON a.accountid=h.accountid AND a.dda=date(date_sub(h.ddaa,interval 90 day)) #90日访问用户统计 101 | GROUP BY 1 ; 102 | 103 | 104 | 105 | 106 | 107 | 108 | -- 109 | -- 110 | -- 111 | -- 112 | -- 113 | -- 114 | -- 【test】 115 | -- 每日注册: 116 | -- 次日留存: 117 | -- 7日留存: 118 | -- 15日留村: 119 | -- 30日留存: 120 | -- 121 | -- select DATE(date_add(NOW(),interval 7 day)) from dual; 122 | -- 123 | -- 1、每日注册: 124 | -- SELECT date(registtime),count(id) 125 | -- FROM account 126 | -- WHERE date(registtime)>'2015-12-31' 127 | -- GROUP BY 1; 128 | -- 129 | -- 2、次日留存: 130 | -- -- SELECT date(dda),count(DISTINCT accountid) 131 | -- -- FROM system_appopenlog 132 | -- -- WHERE date(date_add(NOW(),interval 7 day)) as dda='2016-05-12' 133 | -- -- GROUP BY 1; 134 | -- 3、7日留存: 135 | -- 4、15日留村: 136 | -- 5、30日留存: 137 | -- 138 | -- SELECT dda,count(*) 139 | -- FROM 140 | -- (SELECT id,date(registtime) as dda FROM account WHERE date(registtime)>'2015-12-31' GROUP BY 1,2 ) a 141 | -- JOIN 142 | -- (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) b 143 | -- ON a.id=b.accountid AND a.dda=date(date_sub(ddaa,interval 15 day)) 144 | -- GROUP BY 1; 145 | -- 146 | -- 147 | -- 每日交易用户数: 148 | -- SELECT date(createtime),count(DISTINCT accountid) 149 | -- FROM account_trade 150 | -- WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND date(createtime)>'2015-12-31' 151 | -- GROUP BY 1 ; 152 | -- 153 | -- 次日交易留存: 154 | -- -- 7日交易: 155 | -- -- 15日交易: 156 | -- -- 30日交易: 157 | -- SELECT dda,count(*) 158 | -- FROM 159 | -- (SELECT accountid,date(createtime) as dda 160 | -- FROM account_trade 161 | -- WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND date(createtime)>'2015-12-31' 162 | -- GROUP BY 1,2 ) a 163 | -- JOIN 164 | -- (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 165 | -- UNION 166 | -- SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 ) b 167 | -- ON a.accountid=b.accountid AND a.dda=b.ddaa 168 | -- GROUP BY 1; 169 | -- 170 | -- SELECT max(opentime),min(opentime) 171 | -- FROM system_appopenlog_bak 172 | -- 173 | -- 174 | -- 175 | -- 176 | -- SELECT dda,count(*) 177 | -- FROM 178 | -- (SELECT accountid,date(createtime) as dda 179 | -- FROM account_trade 180 | -- WHERE biztype in (1,3) and inouttype=1 AND `status`=20 AND date(createtime)>'2015-12-31' 181 | -- GROUP BY 1,2 ) a 182 | -- JOIN 183 | -- (SELECT accountid,date(opentime) as ddaa FROM system_appopenlog WHERE date(opentime)>'2015-12-31'GROUP BY 1,2 184 | -- UNION 185 | -- SELECT accountid,date(opentime) as ddaa FROM system_appopenlog_bak WHERE date(opentime)>'2015-12-31' GROUP BY 1,2 ) b 186 | -- ON a.accountid=b.accountid AND a.dda=date(date_sub(ddaa,interval 30 day)) 187 | -- GROUP BY 1; 188 | -------------------------------------------------------------------------------- /每日登录与签到: -------------------------------------------------------------------------------- 1 | #每日登录&签到用户数 2 | SELECT dda,countdenglu,countqiandao 3 | FROM 4 | ( 5 | SELECT date(opentime) as dda,count(DISTINCT accountid) as countdenglu 6 | FROM system_appopenlog 7 | GROUP BY 1 8 | ) a 9 | JOIN 10 | ( 11 | SELECT date(createtime) as ddaa,count(*) as countqiandao 12 | FROM score_gain_stream 13 | WHERE `status`=1 AND date(createtime)>'2016-08-01' 14 | GROUP BY 1 15 | ) b 16 | ON a.dda=b.ddaa ; 17 | -------------------------------------------------------------------------------- /每日资金流动: -------------------------------------------------------------------------------- 1 | 【每日交易额】 2 | #每日交易额汇总 3 | SELECT a.t,a.aa,a.bb,a.cc,a.dd,a.ee,0,0,b.aa,b.bb,b.cc,b.dd,b.ee,c.aa,c.bb,c.ee 4 | FROM 5 | (SELECT date(createtime) as t,sum(amount) aa,sum(assetamount) bb,sum(bonusamount) cc,sum(couponamount) dd ,sum(amount+assetamount+bonusamount+couponamount) ee 6 | FROM da_account_trade 7 | where biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-01-01' 8 | GROUP BY 1) a 9 | JOIN 10 | (SELECT date(createtime) as t,sum(amount) aa,sum(assetamount) bb,sum(bonusamount) cc ,sum(couponamount) dd,sum(amount+assetamount+bonusamount+couponamount) ee 11 | FROM da_account_trade 12 | where biztype=1 AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-01-01' 13 | GROUP BY 1) b 14 | ON a.t=b.t 15 | JOIN 16 | (SELECT date(createtime) as t,sum(amount) aa ,sum(assetamount) bb ,sum(amount+assetamount+bonusamount+couponamount)ee 17 | FROM da_account_trade 18 | where biztype=3 AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-01-01' 19 | GROUP BY 1) c 20 | ON b.t=c.t; 21 | 22 | 23 | 【每日提现】 24 | SELECT a.t,a.aa,b.bb,c.cc 25 | FROM 26 | (SELECT date(createtime) as t,sum(amount+assetamount+bonusamount+couponamount) aa 27 | FROM da_account_trade 28 | WHERE biztype=4 AND inouttype=2 AND `status` in (5,6,20) AND date(createtime)='2016-01-11' 29 | GROUP BY 1) a 30 | JOIN 31 | #优选理财回款 32 | (SELECT date(createtime) as t,sum(amount-profit) bb 33 | FROM account_inout 34 | WHERE biztype=1 AND inouttype=2 AND date(createtime)='2016-01-11' 35 | GROUP BY 1) b 36 | ON a.t=b.t 37 | JOIN 38 | #点点宝赎回 39 | (SELECT date(createtime) as t,sum(amount+assetamount+bonusamount+couponamount) cc 40 | FROM da_account_trade 41 | WHERE biztype=3 AND inouttype=2 AND `status` in (5,6,20) AND date(createtime)='2016-01-11' 42 | GROUP BY 1) c 43 | ON b.t=c.t; 44 | -------------------------------------------------------------------------------- /活跃时间段分布: -------------------------------------------------------------------------------- 1 | 【活跃时间段分布】 2 | SELECT hour,count(hour) 3 | FROM 4 | (SELECT accountid,hour(createtime) as hour 5 | FROM da_account_trade 6 | where biztype in (1,3) AND inouttype=1 AND `status`=20 7 | AND accountid in (SELECT id FROM ds_account WHERE date(registtime)>'2015-05-31' 8 | AND commandid is null AND iDdate is not null 9 | AND channel NOT in ('quanmama','kumi','dandanzuan','xiaoniao','8868','dianju')) 10 | GROUP BY 1 11 | HAVING count(accountid)>1 ) aaa 12 | GROUP BY 1 13 | ORDER BY 2 DESC; 14 | #注册用户的注册时间活跃时间段分布 15 | SELECT hour,count(id) 16 | FROM 17 | (SELECT id,hour(registtime) as hour 18 | FROM da_account 19 | WHERE commandid is null 20 | AND date(registtime)>'2015-5-31' AND channel NOT in ('quanmama','kumi','dandanzuan','xiaoniao','8868','dianju')) aaa 21 | GROUP BY 1 22 | ORDER BY 2 DESC; 23 | 24 | 25 | -------------------------------------------------------------------------------- /渠道交易分布(新版): -------------------------------------------------------------------------------- 1 | SELECT xxx.channel,aaa.count,bbb.coscot,ccc.count,ccc.sum,eee.sum,fff.sum,ggg.count,hhh.count,iii.sum 2 | FROM 3 | (SELECT channel from da_account GROUP BY 1) xxx 4 | LEFT JOIN 5 | (#1、时间--注册渠道的注册人数 6 | SELECT channel,count(id) as count FROM da_account WHERE date(registtime)='2016-02-15' GROUP BY 1) aaa 7 | ON xxx.channel=aaa.channel 8 | LEFT JOIN 9 | (#2、时间--注册渠道的绑卡人数 10 | SELECT xy,sum(coss+cott) as coscot 11 | FROM 12 | (SELECT aaa.channel,ifnull(cos,0) as coss,bbb.channel as xy,ifnull(cot,0) as cott 13 | FROM 14 | (#【1】交易表绑卡人数 15 | SELECT channel,ifnull(count(accountid),0) as cos 16 | FROM 17 | (SELECT accountid,createtime FROM da_account_trade WHERE biztype=4 AND inouttype=1 AND `status`=20 18 | and date(createtime)='2016-02-15' 19 | GROUP BY 1) a 20 | JOIN 21 | (SELECT id,channel from da_account WHERE date(registtime)='2016-02-15' ) b 22 | ON a.accountid=b.id 23 | GROUP BY 1 ) aaa 24 | LEFT JOIN 25 | (#【2】鉴权表绑卡人数 26 | SELECT channel,count(accountid) as cot 27 | FROM 28 | (SELECT accountid,createtime 29 | FROM account_independent_authentication 30 | WHERE date(createtime)='2016-02-15' AND `status`=20 31 | GROUP BY 1) a 32 | JOIN 33 | (SELECT id,channel from da_account WHERE date(registtime)='2016-02-15') b 34 | ON a.accountid=b.id 35 | GROUP BY 1) bbb 36 | ON aaa.channel=bbb.channel 37 | UNION 38 | SELECT aaa.channel,ifnull(cos,0) as coss,bbb.channel as xy,ifnull(cot,0) as cott 39 | FROM 40 | (#【1】交易表绑卡人数 41 | SELECT channel,count(accountid) as cos 42 | FROM 43 | (SELECT accountid,createtime FROM da_account_trade WHERE biztype=4 AND inouttype=1 AND `status`=20 44 | and date(createtime)='2016-02-15' 45 | GROUP BY 1) a 46 | JOIN 47 | (SELECT id,channel from da_account WHERE date(registtime)='2016-02-15') b 48 | ON a.accountid=b.id 49 | GROUP BY 1 ) aaa 50 | RIGHT JOIN 51 | (#【2】鉴权表绑卡人数 52 | SELECT channel,count(accountid) as cot 53 | FROM 54 | (SELECT accountid,createtime 55 | FROM account_independent_authentication 56 | WHERE date(createtime)='2016-02-15' AND `status`=20 57 | GROUP BY 1) a 58 | JOIN 59 | (SELECT id,channel from da_account WHERE date(registtime)='2016-02-15') b 60 | ON a.accountid=b.id 61 | GROUP BY 1) bbb 62 | ON aaa.channel=bbb.channel ) aaaa 63 | GROUP BY 1 ) bbb 64 | ON xxx.channel=bbb.xy 65 | LEFT JOIN 66 | (#3、时间--渠道的首次交易人数 67 | SELECT b.channel as channel,count(accountid) as count,sum(amount+assetamount+couponamount+couponamount) as sum 68 | FROM 69 | (SELECT accountid,amount,assetamount,bonusamount,couponamount 70 | FROM da_account_trade 71 | WHERE biztype in (1,3) AND inouttype=1 and `status`=20 AND date(createtime)='2016-02-15' 72 | AND accountid not in (SELECT accountid 73 | FROM da_account_trade 74 | WHERE biztype in (1,3) AND inouttype=1 and `status`=20 AND date(createtime)<'2016-02-15') 75 | GROUP BY 1) a 76 | LEFT JOIN 77 | (SELECT id,channel FROM da_account WHERE date(registtime)='2016-02-15') b 78 | ON b.id = a.accountid 79 | GROUP BY 1) ccc 80 | ON xxx.channel=ccc.channel 81 | LEFT JOIN 82 | (#4、新用户交易额 83 | SELECT channel,sum(sum) as sum 84 | FROM 85 | (SELECT accountid,sum(amount+assetamount+couponamount+bonusamount) as sum FROM da_account_trade 86 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2016-02-15' 87 | AND accountid not in (SELECT accountid FROM da_account_trade 88 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-02-15') GROUP BY 1) a 89 | LEFT JOIN 90 | (SELECT id,channel FROM da_account) b 91 | ON a.accountid = b.id 92 | GROUP BY 1) eee 93 | ON xxx.channel=eee.channel 94 | LEFT JOIN 95 | (#6、新老用户交易额 96 | SELECT channel,sum(sum) as sum 97 | FROM 98 | (SELECT accountid,sum(amount+assetamount+bonusamount+couponamount) as sum 99 | FROM da_account_trade 100 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2016-02-15') a 101 | LEFT JOIN 102 | (SELECT id,channel FROM da_account) b 103 | ON a.accountid = b.id 104 | GROUP BY 1) fff 105 | ON xxx.channel=fff.channel 106 | LEFT JOIN 107 | (-- 【渠道累计】 108 | #7、渠道累计注册人数 109 | SELECT channel,count(id) as count 110 | FROM da_account 111 | WHERE date(registtime) < '2016-02-16' 112 | GROUP BY 1) ggg 113 | ON xxx.channel=ggg.channel 114 | LEFT JOIN 115 | (#8、渠道累计交易人数 116 | SELECT b.channel as channel,count(*) as count 117 | FROM 118 | (SELECT accountid,amount,assetamount,bonusamount,couponamount FROM da_account_trade 119 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-02-16' 120 | GROUP BY 1 ) a 121 | LEFT JOIN 122 | (SELECT id,channel FROM da_account) b 123 | ON a.accountid = b.id 124 | GROUP BY 1) hhh 125 | ON xxx.channel=hhh.channel 126 | LEFT JOIN 127 | (#9、渠道累计交易金额 128 | SELECT b.channel as channel,sum(a.amount+a.assetamount+a.bonusamount+a.couponamount) as sum 129 | FROM 130 | (SELECT * 131 | FROM da_account_trade 132 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-02-16') a 133 | LEFT JOIN 134 | (SELECT id,channel FROM da_account) b 135 | ON a.accountid = b.id 136 | GROUP BY 1) iii 137 | ON xxx.channel=iii.channel 138 | WHERE xxx.channel is not null 139 | GROUP BY 1; 140 | -------------------------------------------------------------------------------- /渠道转化率: -------------------------------------------------------------------------------- 1 | SELECT aaa.channel,aaa.count,bbb.count,ccc.count 2 | from 3 | ( 4 | #各渠道注册用户 5 | SELECT channel,count(id) as count 6 | FROM da_account 7 | WHERE date_format(registtime,'%Y-%m')='2015-12' 8 | AND channel in ('360','xiaomi','yingyongb','baiducpd','lianxiang','baidu','tengxun','huawei', 9 | 'guanwang','jinritoutiao','meizu','pp','taobao','oppo','wandoujia','jinritoutiao2','wandoujiacpd', 10 | 'UCCPD','360yuansheng','jinritoutiao3','sougou','jinritoutiao1','PPcpd') 11 | GROUP BY 1 12 | ORDER BY 2 DESC ) aaa 13 | JOIN 14 | ( 15 | #各渠道绑卡用户 16 | SELECT channel,count(DISTINCT(id)) as count 17 | FROM ds_account 18 | WHERE IDdate is not null 19 | AND date_format(registtime,'%Y-%m')='2015-12' 20 | AND channel in ('360','xiaomi','yingyongb','baiducpd','lianxiang','baidu','tengxun','huawei', 21 | 'guanwang','jinritoutiao','meizu','pp','taobao','oppo','wandoujia','jinritoutiao2','wandoujiacpd', 22 | 'UCCPD','360yuansheng','jinritoutiao3','sougou','jinritoutiao1','PPcpd') 23 | GROUP BY 1 24 | ORDER BY 2 DESC ) bbb 25 | ON aaa.channel=bbb.channel 26 | JOIN 27 | ( 28 | #各渠道交易用户 29 | SELECT b.channel as channel,count(DISTINCT(accountid)) as count 30 | FROM 31 | (SELECT accountid FROM da_account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 32 | AND accountid in (SELECT id FROM ds_account 33 | WHERE IDdate is not null AND date_format(registtime,'%Y-%m')='2015-12' 34 | AND channel in ('360','xiaomi','yingyongb','baiducpd','lianxiang','baidu','tengxun','huawei', 35 | 'guanwang','jinritoutiao','meizu','pp','taobao','oppo','wandoujia','jinritoutiao2','wandoujiacpd', 36 | 'UCCPD','360yuansheng','jinritoutiao3','sougou','jinritoutiao1','PPcpd'))) a 37 | JOIN 38 | (SELECT id,channel 39 | FROM da_account 40 | WHERE date_format(registtime,'%Y-%m')='2015-12' 41 | AND channel in ('360','xiaomi','yingyongb','baiducpd','lianxiang','baidu','tengxun','huawei', 42 | 'guanwang','jinritoutiao','meizu','pp','taobao','oppo','wandoujia','jinritoutiao2','wandoujiacpd', 43 | 'UCCPD','360yuansheng','jinritoutiao3','sougou','jinritoutiao1','PPcpd')) b 44 | on a.accountid=b.id 45 | GROUP BY 1 46 | ORDER BY 2 DESC ) ccc 47 | ON bbb.channel=ccc.channel 48 | GROUP BY 1; 49 | -------------------------------------------------------------------------------- /用户星座: -------------------------------------------------------------------------------- 1 | select nnd,count(*) 2 | from 3 | (select case 4 | when substring(IDdate,6,5) BETWEEN "03-21" AND '04-19' then '白羊座' 5 | when substring(IDdate,6,5) BETWEEN "04-20" AND '05-20' then '金牛座' 6 | when substring(IDdate,6,5) BETWEEN "05-21" AND '06-21' then '双子座' 7 | when substring(IDdate,6,5) BETWEEN "06-22" AND '07-22' then '巨蟹座' 8 | when substring(IDdate,6,5) BETWEEN "07-23" AND '08-22' then '狮子座' 9 | when substring(IDdate,6,5) BETWEEN "08-23" AND '09-22' then '处女座' 10 | when substring(IDdate,6,5) BETWEEN "09-23" AND '10-23' then '天秤座' 11 | when substring(IDdate,6,5) BETWEEN "10-24" AND '11-22' then '天蝎座' 12 | when substring(IDdate,6,5) BETWEEN "11-23" AND '12-21' then '射手座' 13 | when substring(IDdate,6,5) BETWEEN "12-22" AND '01-19' then '摩羯座' 14 | when substring(IDdate,6,5) BETWEEN "01-20" AND '02-18' then '水瓶座' 15 | when substring(IDdate,6,5) BETWEEN "02-19" AND '03-20' then '双鱼座' end as nnd 16 | FROM ds_account 17 | WHERE IDdate is not null) a 18 | group by nnd 19 | order by 2 DESC; 20 | -------------------------------------------------------------------------------- /账户余额: -------------------------------------------------------------------------------- 1 | SELECT a.da, 2 | a.sum as asum, 3 | b.sum as bsum, 4 | ifnull(c.count,0), 5 | 0, 6 | sum(a.sum+b.sum+ifnull(c.count,0)) as total1, 7 | d.sum as dsum, 8 | e.sum as esum, 9 | sum(d.sum+e.sum) as total2, 10 | sum(a.sum+b.sum+ifnull(c.count,0))-sum(d.sum+e.sum), 11 | f.sum as fsum, 12 | d.sum/sum(d.sum+e.sum) as per1, 13 | e.sum/sum(d.sum+e.sum) as per2 14 | FROM 15 | (#1、点点宝赎回 16 | SELECT date(createtime) as da,sum(amount+assetamount+bonusamount+couponamount) as sum 17 | FROM account_trade 18 | WHERE biztype=3 AND inouttype=2 AND `status`=20 AND date(createtime)>'2016-07-31' 19 | GROUP BY 1 ) a 20 | LEFT JOIN 21 | (#2、优选理财回款 (此处的优选理财回款不用减去收益) 22 | SELECT date(createtime) as da,sum(amount) as sum 23 | FROM account_inout 24 | WHERE biztype=1 AND inouttype=2 AND date(createtime)>'2016-02-20' 25 | GROUP BY 1 ) b 26 | ON a.da=b.da 27 | LEFT JOIN 28 | (#3、绑卡充值人数 29 | SELECT date(createtime) as da,count(accountid) as count 30 | FROM account_trade 31 | WHERE biztype=4 AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-02-20' 32 | GROUP BY 1 ) c 33 | ON a.da=c.da 34 | LEFT JOIN 35 | (#4、余额再次投资 36 | SELECT date(createtime) as da,sum(assetamount) as sum 37 | FROM account_trade 38 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)>'2016-02-20' 39 | GROUP BY 1 ) d 40 | ON a.da=d.da 41 | LEFT JOIN 42 | (#5、提现 43 | SELECT date(createtime) as da,sum(amount+assetamount+bonusamount+couponamount) as sum 44 | FROM account_trade 45 | WHERE biztype=4 and inouttype=2 and `status` in (5,6,20) AND date(createtime)>'2016-02-20' 46 | GROUP BY 1 ) e 47 | ON a.da=e.da 48 | LEFT JOIN 49 | (#账户余额剩余(前一天到凌晨为止所有账户上面的累计账户余额) 50 | SELECT date(saveday) as da,sum(asset) as sum 51 | from ds_save_accountbal 52 | GROUP BY 1 ) f 53 | ON a.da=f.da 54 | GROUP BY 1; 55 | 56 | -- SELECT accountid,sum(asset) as sum 57 | -- from ds_save_accountbal 58 | -- WHERE date(saveday)='2016-07-04' 59 | -- GROUP BY 1 60 | -- LIMIT 10 61 | -------------------------------------------------------------------------------- /邀请与渠道: -------------------------------------------------------------------------------- 1 | #【注册用户】 2 | SELECT a.dda,count1,count2,count1/(count1+count2),count2/(count1+count2),count3,count4,count3/(count3+count4),count4/(count4+count3) 3 | from 4 | (#1、【每日渠道注册用户数】 5 | SELECT date(registtime) dda,count(id) count1 FROM account WHERE date(registtime)>'2016-01-25' AND commandid is null GROUP BY 1) a 6 | JOIN 7 | (#2、【每日邀请注册用户总数】 8 | SELECT date(registtime) dda,count(id)as count2 FROM account WHERE date(registtime)>'2016-01-25' AND commandid is not null GROUP BY 1) b 9 | ON a.dda=b.dda 10 | JOIN 11 | (#【交易用户】3、当日新增用户之中来自渠道途径的用户数: 12 | SELECT date(createtime) as dda,count(DISTINCT(accountid)) as count3 13 | FROM account_trade 14 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2016-08-11' 15 | AND accountid not in (SELECT accountid FROM account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-08-11') 16 | AND accountid in (SELECT id FROM account WHERE commandid is null)) c 17 | ON a.dda=c.dda 18 | JOIN 19 | (#4、当日新增用户之中来自邀请途径的用户数: 20 | SELECT date(createtime) as dda,count(DISTINCT accountid) as count4 21 | FROM account_trade 22 | WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)='2016-08-11' 23 | AND accountid not in (SELECT accountid FROM account_trade WHERE biztype in (1,3) AND inouttype=1 AND `status`=20 AND date(createtime)<'2016-08-11') 24 | AND accountid in (SELECT id FROM account WHERE commandid is not null)) d 25 | ON a.dda=d.dda; 26 | 27 | 28 | SELECT * FROM da_account limit 10; 29 | -------------------------------------------------------------------------------- /首次交易: -------------------------------------------------------------------------------- 1 | SELECT 2 | accountid, 3 | createtime, 4 | sum, 5 | itemtitle, 6 | totalperiods 7 | FROM 8 | ( 9 | SELECT 10 | accountid, 11 | itemid, 12 | createtime, 13 | sum( 14 | amount + assetamount + bonusamount + couponamount 15 | ) AS sum 16 | FROM 17 | account_trade 18 | WHERE 19 | biztype IN (1, 3) 20 | AND inouttype = 1 21 | AND `status` = 20 22 | AND date(createtime) BETWEEN '2016-08-08' 23 | AND '2016-08-10' 24 | AND accountid NOT IN ( 25 | SELECT 26 | accountid 27 | FROM 28 | account_trade 29 | WHERE 30 | biztype IN (1, 3) 31 | AND inouttype = 1 32 | AND `status` = 20 33 | AND date(createtime) < '2016-08-08' 34 | GROUP BY 35 | 1 36 | ) 37 | AND accountid IN ( 38 | SELECT 39 | id 40 | FROM 41 | account 42 | WHERE 43 | channel = 'liuliangbao' 44 | ) 45 | GROUP BY 46 | id 47 | ) a 48 | JOIN ( 49 | SELECT 50 | id, 51 | itemtitle, 52 | totalperiods 53 | FROM 54 | selfitem 55 | ) b ON a.itemid = b.id; 56 | --------------------------------------------------------------------------------