質問編集履歴

1

コード使用

2022/03/04 04:16

投稿

karun
karun

スコア18

test CHANGED
File without changes
test CHANGED
@@ -3,6 +3,7 @@
3
3
  現時点のテーブル構造はいかになります
4
4
 
5
5
 
6
+ ```
6
7
  CREATE TABLE `table` (
7
8
  `id` varchar(64) NOT NULL,
8
9
  `code` varchar(64) NOT NULL,
@@ -13,6 +14,7 @@
13
14
  KEY `idx_comment_code` (`comment`,`code`),
14
15
  KEY `idx_updated_at` (`update_date`)
15
16
  )
17
+ ```
16
18
  上記のようなテーブル構造のテーブルがあります
17
19
  codeは任意のcodeが入っている(例えばA~Eまでがとある条件によって指定されている感じです)
18
20
  commentは一意の値が入っているが例外的に同じcommentも入ることがある
@@ -22,8 +24,10 @@
22
24
  2.codeを条件に重複したcommentを1としcodeごとのcomment数が知りたい
23
25
 
24
26
  純粋に
27
+ ```ここに言語を入力
25
28
  select count(code) from table where code="A"
26
29
  select count(distinct comment) from table where code="A"
30
+ ```
27
31
  とした場合取得するまでに時間がかかってしまいます
28
32
  こちらをいかに早く取得できる方法はありますでしょうか?
29
33
  宜しくお願いいたします。