MYSQL 統計查詢

2021-07-05 04:04:40 字數 1836 閱讀 7553

mysql-統計查詢

mysql查詢統計報表

獲取當前時間截

[html] view plaincopyprint?

select unix_timestamp(now())

獲取當天零時時間截

[html] view plaincopyprint?

select unix_timestamp(curdate())

統計當天每個小時段的記錄數量

[html] view plaincopyprint?

select count(*) as statnum, date_format(from_unixtime(created),'%h') as time from qxm30_point_log where created > unix_timestamp(curdate()) group by date_format(from_unixtime(created),'%h')

統計當天每個小時段的使用者數,去重複使用者記錄數 distinct修飾去重複

[html] view plaincopyprint?

select count(distinct uid) as statnum, date_format(from_unixtime(created),'%h') as time from qxm30_point_log where created > unix_timestamp(curdate()) group by date_format(from_unixtime(created),'%h')

統計某月每天的記錄數量

[html] view plaincopyprint?

select count(*) as statnum, date_format(from_unixtime(created),'%m-%d') as time from qxm30_point_log where created between unix_timestamp('2013-9-11') and (unix_timestamp('2013-9-11')+3600*24*30) group by date_format(from_unixtime(created),'%m-%d')

統計某月每天的使用者數量

[html] view plaincopyprint?

select count(distinct uid) as statnum, date_format(from_unixtime(created),'%m-%d') as time from qxm30_point_log where created between unix_timestamp('2013-9-11') and (unix_timestamp('2013-9-11')+3600*24*30) group by date_format(from_unixtime(created),'%m-%d')

統計某月每天的人均記錄數量

[html] view plaincopyprint?

select count(*)/count(distinct uid) as statnum, date_format(from_unixtime(created),'%m-%d') as time from qxm30_point_log where created between unix_timestamp('2013-9-11') and (unix_timestamp('2013-9-11')+3600*24*30) group by date_format(from_unixtime(created),'%m-%d')

另附圖表外掛程式highcharts

頂2踩

mysql遞迴查詢統計 mysql遞迴查詢

樣例資料 create table treenodes id int primary key,nodename varchar 20 pid int select from treenodes id nodename pid 1 a 0 2 b 1 3 c 1 4 d 2 5 e 2 6 f 3 7...

mysql統計查詢優化 Mysql查詢優化

效能涉及的層面很多,但是在操作層面,主要有表結構設計優化 索引優化和查詢優化 查詢的生命週期大致可以分為,從客戶端 到服務端 在伺服器上解析 生成執行計畫 執行 返回結果給客戶端 sql執行流程 具體優化技巧 1.消除外連線 2.消除子查詢 盡量用join代替子查詢,雖說mysql查詢優化器會進行優...

Mysql 列轉行統計查詢 行轉列統計查詢

之前看過一篇博文寫得非常好,看後就很容易讓人理解,博文位址為 最近在群裡又碰到乙個朋友說起,於是記錄一下 假設表名為t.表裡有六個欄位p1,p2,p3,s1,s2,s3 現在想得到 p1 100 時s1值的總和 p2 100 時s2值的總和 p3 100 時s3值的總和 建立表 create tab...