teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

編集

2018/06/14 05:32

投稿

joeast
joeast

スコア26

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- ```mysql
1
+ ```sql
2
2
  select (select count(*)+1 from (select usf_sid, count(*) as ct from usfavo group by usf_sid) as t1 where t1.ct > t2.ct ) as rank from (select usf_sid, count(*) as ct from usfavo group by usf_sid) as t2 where usf_sid=1
3
3
  ```
4
4
 
@@ -18,7 +18,7 @@
18
18
  よろしくお願いいたします。
19
19
 
20
20
 
21
- ```mysql
21
+ ```sql
22
22
  select count(*)+1
23
23
  from (select usf_sid, count(*) as ct1 from usfavo group by usf_sid) t1
24
24
  where ct1 > (select count(*) from usfavo where usf_sid=1)

2

解決いたしました

2018/06/14 05:32

投稿

joeast
joeast

スコア26

title CHANGED
File without changes
body CHANGED
@@ -15,4 +15,15 @@
15
15
  with句は試してみたのですが、mysqlのバージョンが5.7な為か、使用できませんでした。
16
16
  その他の方法も探してみたのですが、明確な答えが出せなかった為質問させていただきました。
17
17
  お分かりの方がおられましたらご教示いただけないでしょうか。
18
- よろしくお願いいたします。
18
+ よろしくお願いいたします。
19
+
20
+
21
+ ```mysql
22
+ select count(*)+1
23
+ from (select usf_sid, count(*) as ct1 from usfavo group by usf_sid) t1
24
+ where ct1 > (select count(*) from usfavo where usf_sid=1)
25
+ ```
26
+
27
+ こちらのコードで解決いたしました。
28
+ ご回答いただいた皆様、ありがとうございます。
29
+ ご指摘いただいた点など参考にさせていただき、勉強してきます。

1

コードの記述について更新しました

2018/06/14 05:32

投稿

joeast
joeast

スコア26

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,6 @@
1
+ ```mysql
1
2
  select (select count(*)+1 from (select usf_sid, count(*) as ct from usfavo group by usf_sid) as t1 where t1.ct > t2.ct ) as rank from (select usf_sid, count(*) as ct from usfavo group by usf_sid) as t2 where usf_sid=1
3
+ ```
2
4
 
3
5
  現在このようなクエリを実行しております。
4
6
  内容は、usfavoテーブルをusf_sidでグループ化しその数をカウントします。