作成日:2018-09-27,
更新日:2023-01-15
基本
グループにしたときの各総数じゃなくて、レコード数が欲しい
| 元データ | groupしたときの各総数 | 取得したいデータ | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
クエリ
「count(〇〇〇)」や「group by 〇〇〇」を使わず「count(distinct 〇〇〇)」を使う
select count(distinct `name`) _cnt_name from 〇〇〇
グループにしたときの各総数じゃなくて、レコード数が欲しい
| 元データ | groupしたときの各総数 | 取得したいデータ | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
「count(〇〇〇)」や「group by 〇〇〇」を使わず「count(distinct 〇〇〇)」を使う
select count(distinct `name`) _cnt_name from 〇〇〇