回答編集履歴

5

削除

2019/03/22 04:10

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -8,68 +8,8 @@
8
8
 
9
9
  ```SQL
10
10
 
11
- select タイプ, 最終件数/最終分割数 - 件数 as 振分数
12
-
13
- from (
14
-
15
- select fltr.タイプ, (tgt.全件数 + src.件数) AS 最終件数, fltr.件数
16
-
17
- , (select count(*)
11
+ --ちょっと考え違いしてたので、削除
18
-
19
- from (
20
-
21
- select 'A' as タイプ, count(*) as 件数 from ta
22
-
23
- union all select 'B', count(*) from tb
24
-
25
- union all select 'C', count(*) from tc
26
-
27
- union all select 'D', count(*) from td
28
-
29
- ) list
30
-
31
- where ((tgt.全件数 + src.件数) / tgt.分割数)>list.件数
32
-
33
- ) as 最終分割数
34
-
35
- from (
36
-
37
- select 'A' as タイプ, count(*) as 件数 from ta
38
-
39
- union all select 'B', count(*) from tb
40
-
41
- union all select 'C', count(*) from tc
42
-
43
- union all select 'D', count(*) from td
44
-
45
- ) fltr
46
-
47
- , (
48
-
49
- select sum(件数) as 全件数, count(*) as 分割数
50
-
51
- from (
52
-
53
- select count(*) as 件数 from ta
54
-
55
- union all select count(*) from tb
56
-
57
- union all select count(*) from tc
58
-
59
- union all select count(*) from td
60
-
61
- ) step1
62
-
63
- ) tgt
64
-
65
- , (select count(*) as 件数 from tx) src
66
-
67
- where ((tgt.全件数 + src.件数) / tgt.分割数)>fltr.件数
68
-
69
- ) as culc
70
12
 
71
13
  ```
72
14
 
73
15
  ※with式が使えるDBMSならもうちょっと記述はシンプルになるかと思います。
74
-
75
- 質問での各件数なら、結果は、(A=80,B=70,C=50)が返却されます。

4

追記

2019/03/22 04:10

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -71,3 +71,5 @@
71
71
  ```
72
72
 
73
73
  ※with式が使えるDBMSならもうちょっと記述はシンプルになるかと思います。
74
+
75
+ 質問での各件数なら、結果は、(A=80,B=70,C=50)が返却されます。

3

補正

2019/03/22 03:39

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  union all select 'C', count(*) from tc
42
42
 
43
- union all select 'D', count(*) from tD
43
+ union all select 'D', count(*) from td
44
44
 
45
45
  ) fltr
46
46
 

2

追記

2019/03/22 03:35

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -69,3 +69,5 @@
69
69
  ) as culc
70
70
 
71
71
  ```
72
+
73
+ ※with式が使えるDBMSならもうちょっと記述はシンプルになるかと思います。

1

推敲

2019/03/22 03:33

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -1,4 +1,4 @@
1
- どういう結果になて欲しいか、サンプルがあった方が良いと思いますが、テーブルの件数からという事なので、SQLで求めてみました。
1
+ どういう結果になて欲しいか、サンプルがあった方が良いと思いますが、テーブルの件数からという事なので、SQLで求めてみました。
2
2
 
3
3
  ただ、割った数の余りの扱いまでは考慮していません。
4
4