MySQL查詢統計,統計唯一值並分組

2022-07-17 19:54:13 字數 936 閱讀 3721

做個筆記

sqlyog客戶端訪問mysql伺服器

統計資料:次數總數, 次數成功率,物件(obj)總數,物件(obj)成功率

要求:按時間排序和分組

sql語句如下:

1

select

2 a.date as

`日期`,

3 a.total as

`總次數`,

4 a.objs as

`總物件數`,

5round(a.failed / a.total *

100, 2) as

`失敗次數比率`,

6round(a.obj_failed/ a.objs *

100, 2) as

`物件失敗率`

7from

8 (select

9count(1) as

`total`,

10count(distinct(`obj_id`)) as

`objs`,

11count(if(`description` like

'%object failed%

', 1, null)) as

`failed`,

12count(distinct(if(`description` like

'%object failed%

', `obj_id`, null))) as

`obj_failed`,

13 date(`created_at`) as

`date`

14from `mydb.my_table` where `created_at` >

'2016-03-07 0'15

group

by`date`

16order

by `date` desc)17

as a

mysql統計查詢並查詢字段

select count 1 ifvote d.voteitemid from tp votedetail d where d.fgsid and d.voteid 943306615853940736 and d.personid 011217033621526565 order by d.vot...

MYSQL 統計查詢

mysql 統計查詢 mysql查詢統計報表 獲取當前時間截 html view plaincopyprint?select unix timestamp now 獲取當天零時時間截 html view plaincopyprint?select unix timestamp curdate 統計當...

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

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