浠g爜绠€娲佷富涔?----鐢ㄤ竴鏉QL缁熻鐣欏瓨銆丩TV銆佷粯璐圭暀瀛?/a>

Posted TecRicardo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浠g爜绠€娲佷富涔?----鐢ㄤ竴鏉QL缁熻鐣欏瓨銆丩TV銆佷粯璐圭暀瀛?/a>相关的知识,希望对你有一定的参考价值。

搴忚█

鍏充簬甯歌鐨勭粺璁¤鍙ョ綉涓婃病浠€涔堟枃绔狅紝鍩烘湰閮戒笉鏄緢绠€娲佹垨鑰呬竴鏉℃潯SQL鐨勫爢鍙犲嚭缁熻璇彞锛屽悇绉嶅瓙鏌ヨ宓屽涓ラ噸銆傚垰濂芥渶杩戝張閲嶅啓缁熻琛紝璁板綍涓€涓嬫柊鏂规硶鐨勬垚鏋滐紝椤轰究鏂逛究骞垮ぇ闈㈠悜鎼滅储缂栫▼鐨勫摜浠湁涓€濊矾鍙傝€冿紝鏈変笉瀵圭殑鍦版柟娆㈣繋澶х鎸囨鍝?!馃槝

鐣欏瓨缁熻

  • 鐣欏瓨缁熻鏍稿績鍔熻兘鍙渶瑕?strong>涓や釜琛?/strong>涓殑涓や釜瀛楁灏辫兘缁熻娓呮锛屽叧閿〃鍙婂瓧娈靛涓嬶細

鐢ㄦ埛琛?strong>users锛屽寘鍚玼ser_id锛?strong>鐢ㄦ埛ID锛夊拰reg_time锛?strong>娉ㄥ唽鏃ユ湡锛夌殑瀛楁銆?/p>

鐢ㄦ埛ID娉ㄥ唽鏃堕棿
user_idreg_time

鐧诲綍琛?strong>login_log,鍖呭惈user_id锛?strong>鐢ㄦ埛ID锛夊拰login_time锛?strong>鐧诲綍鏃堕棿锛?/p>

鐢ㄦ埛ID鐧诲綍鏃堕棿
user_idlogin_time
  • 鍒涘缓骞舵坊鍔犺〃鏍兼祴璇曟暟鎹紝2寮犺〃鐨勬椂闂撮兘鏄?strong>datetime绫诲瀷 YYYY-MM-DD HH:MM:SS
-- 鐢ㄦ埛娉ㄥ唽琛?create table users(user_id varchar(10) primary key,reg_time datetime);

insert into users values
(\'u_01\',\'2020-01-01 09:15:00\'),
(\'u_02\',\'2020-01-01 00:04:00\'),
(\'u_03\',\'2020-01-01 22:16:00\'),
(\'u_04\',\'2020-01-01 20:32:00\'),
(\'u_05\',\'2020-01-01 13:59:00\'),
(\'u_06\',\'2020-01-01 21:28:00\'),
(\'u_07\',\'2020-01-01 14:03:00\'),
(\'u_08\',\'2020-01-01 11:00:00\'),
(\'u_09\',\'2020-01-01 23:57:00\'),
(\'u_10\',\'2020-01-01 04:46:00\'),
(\'u_11\',\'2020-01-02 14:21:00\'),
(\'u_12\',\'2020-01-02 11:15:00\'),
(\'u_13\',\'2020-01-02 07:26:00\'),
(\'u_14\',\'2020-01-02 10:34:00\'),
(\'u_15\',\'2020-01-02 08:22:00\'),
(\'u_16\',\'2020-01-02 14:23:00\'),
(\'u_17\',\'2020-01-03 09:20:00\'),
(\'u_18\',\'2020-01-03 11:21:00\'),
(\'u_19\',\'2020-01-03 12:17:00\'),
(\'u_20\',\'2020-01-03 15:26:00\');

-- 鐧婚檰鏃ュ織琛?create table login_log(user_id varchar(10),login_time datetime,primary key(user_id,login_time));

insert into login_log values
(\'u_02\',\'2020-01-02 00:14:00\'),
(\'u_10\',\'2020-01-02 08:32:00\'),
(\'u_03\',\'2020-01-02 09:20:00\'),
(\'u_08\',\'2020-01-02 10:07:00\'),
(\'u_04\',\'2020-01-02 10:29:00\'),
(\'u_09\',\'2020-01-02 11:45:00\'),
(\'u_05\',\'2020-01-02 12:19:00\'),
(\'u_01\',\'2020-01-02 14:29:00\'),
(\'u_15\',\'2020-01-03 00:26:00\'),
(\'u_14\',\'2020-01-03 11:18:00\'),
(\'u_11\',\'2020-01-03 13:18:00\'),
(\'u_16\',\'2020-01-03 14:33:00\'),
(\'u_06\',\'2020-01-04 07:51:00\'),
(\'u_18\',\'2020-01-04 08:11:00\'),
(\'u_07\',\'2020-01-04 09:27:00\'),
(\'u_10\',\'2020-01-04 10:59:00\'),
(\'u_20\',\'2020-01-04 11:51:00\'),
(\'u_03\',\'2020-01-04 12:37:00\'),
(\'u_17\',\'2020-01-04 15:07:00\'),
(\'u_08\',\'2020-01-04 16:35:00\'),
(\'u_01\',\'2020-01-04 19:29:00\'),
(\'u_14\',\'2020-01-05 08:03:00\'),
(\'u_12\',\'2020-01-05 10:27:00\'),
(\'u_15\',\'2020-01-05 16:33:00\'),
(\'u_19\',\'2020-01-06 09:03:00\'),
(\'u_20\',\'2020-01-06 15:26:00\'),
(\'u_04\',\'2020-01-08 11:03:00\'),
(\'u_05\',\'2020-01-08 12:54:00\'),
(\'u_06\',\'2020-01-08 19:22:00\'),
(\'u_13\',\'2020-01-09 10:20:00\'),
(\'u_15\',\'2020-01-09 16:40:00\'),
(\'u_18\',\'2020-01-10 21:34:00\');
  • 鎺ヤ笅鏉ュ氨鏄叧閿楠や簡锛岃仈琛ㄥ苟澶勭悊鏁版嵁锛岀畝鍗曡璇村鐞嗘暟鎹殑鎬濊矾锛?/li>
  • 閫氫織鐨勮锛岀暀瀛樼殑绠楁硶涓?strong>鐧诲綍閭eぉ - 娉ㄥ唽閭eぉ=锛圢锛夌暀銆傛瘮濡傦細娆$暀灏辨槸 鐧诲綍閭eぉ-娉ㄥ唽閭eぉ= (1)鐣?/strong>銆?/li>
  1. 褰撴垜浠袱寮犺〃涓惈鏈?strong>娉ㄥ唽鏃堕棿璺?strong>鐧诲綍鏃堕棿鏃讹紝鏈€鏈寸礌鐨勬兂娉曞簲璇ユ槸杩愮敤涓婅堪渚?鐨勫叕寮忕洿鎺ョ粺璁″嚭鐣欏瓨銆?/li>
  2. 鑱旇〃骞朵互鍚湁娉ㄥ唽鏃堕棿鐨?strong>users琛ㄤ负涓昏〃锛岀櫥褰曡〃涓轰粠琛紝鍚堟垚涓€寮犲ぇ琛ㄦ暟鎹悗瀵规敞鍐屾椂闂村垎缁勭粺璁°€?/li>
  3. 鑱旇〃濡備笅锛氾紙from users left join login_log on users.user_id = login_log.user_id锛夈€佸垎缁勫涓嬶細锛?strong>group by date(users.reg_time)锛?/li>
  4. 浣跨敤sum(datediff(login_time, reg_time) = 1) as 鈥樻鏃ョ暀瀛樼敤鎴锋暟鈥?鏉ュ垎鍒眰鍚屼竴娉ㄥ唽鏃堕棿鐨勫叾浠栧嚑涓含搴︾殑鐢ㄦ埛鐣欏瓨鎯呭喌
鏈€缁堜唬鐮佸涓嬶細~~~~
select 
    date(reg_time) dt,
    count(distinct users.user_id) 鏂板鐢ㄦ埛鏁?
    sum(datediff(login_time,reg_time)=1) 娆℃棩鐣欏瓨鐢ㄦ埛鏁?
    sum(datediff(login_time,reg_time)=3) 鍥涙棩鐣欏瓨鐢ㄦ埛鏁?
    sum(datediff(login_time,reg_time)=7) 鍏棩鐣欏瓨鐢ㄦ埛鏁?
    sum(datediff(login_time,reg_time)=1)/count(distinct users.user_id)*100 娆℃棩鐣欏瓨鐜?
    sum(datediff(login_time,reg_time)=3)/count(distinct users.user_id)*100 鍥涙棩鐣欏瓨鐜?
    sum(datediff(login_time,reg_time)=7)/count(distinct users.user_id)*100 鍏棩鐣欏瓨鐜?from users left join login_log on users.user_id=login_log.user_id
group by date(reg_time);
鏃ユ湡鏂板鐢ㄦ埛鏁?/th>娆℃棩鐣欏瓨鐢ㄦ埛鏁?/th>鍥涙棩鐣欏瓨鐢ㄦ埛鏁?/th>鍏棩鐣欏瓨鐢ㄦ埛鏁?/th>娆℃棩鐣欏瓨鐜?/th>鍥涙棩鐣欏瓨鐜?/th>鍏棩鐣欏瓨鐜?/th>
2020-01-011086380.00%60.00%30.00%
2020-01-02643266.67%50.00%33.33%
2020-01-03432175.00%50.00%25.00%

寰楀嚭鐨勭暀瀛樼粨鏋滀笌鏁版嵁鏄畬鍏ㄤ竴鑷寸殑馃槉锛屽悓鐞嗕篃鑳界敤杩欑鏂规硶寰楀嚭浠樿垂鐣欏瓨鍜孡TV銆傜浉姣斿祵濂楃殑瀛愭煡璇㈢畝娲佷簡寰堝銆?/p>

以上是关于浠g爜绠€娲佷富涔?----鐢ㄤ竴鏉QL缁熻鐣欏瓨銆丩TV銆佷粯璐圭暀瀛?/a>的主要内容,如果未能解决你的问题,请参考以下文章

绠楁硶:鍐掓场鎺掑簭

銆愇?婕旂畻鍦?PY銆戞墧鎺夋父鏍囧崱灏哄悗鐢?PY 鎷兼帴浠g爜

Ajax涔嬭皟鐢ㄤ竴瑷€缃戠珯API鎺ュ彛

銆岄瑙c€岮T4515 [AGC030F] Permutation and Minimum

cakephp鑾峰彇鏈€鍚庝竴鏉ql璇彞