回答編集履歴
2
追記
answer
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
[MySQL 8.0のWindow関数のサンプル集](https://codezine.jp/article/detail/2678)
|
3
3
|
|
4
4
|
```SQL
|
5
|
-
select ユーザーid, sum(購入金額)
|
5
|
+
select p.ユーザーid, u.名前, sum(p.購入金額)
|
6
6
|
from (
|
7
|
-
|
7
|
+
select *
|
8
|
-
|
8
|
+
, row_number() over(partition by ユーザーid order by 購入id desc) as seq
|
9
|
-
|
9
|
+
from 購入履歴テーブル
|
10
|
-
|
10
|
+
where ユーザーid in (・・・)
|
11
|
-
)
|
11
|
+
) p
|
12
|
+
inner join ユーザーテーブル u
|
13
|
+
on p.ユーザーid = u.ユーザーid
|
12
|
-
where seq <= 100
|
14
|
+
where p.seq <= 100
|
13
|
-
group by ユーザーid
|
15
|
+
group by p.ユーザーid, u.名前
|
14
16
|
```
|
1
追記
answer
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
select *
|
8
8
|
, row_number() over(partition by ユーザーid order by 購入id desc) as seq
|
9
9
|
from 購入履歴テーブル
|
10
|
+
where ユーザーid in (・・・)
|
10
11
|
) t
|
11
12
|
where seq <= 100
|
12
13
|
group by ユーザーid
|