回答編集履歴
4
追記
test
CHANGED
@@ -79,3 +79,27 @@
|
|
79
79
|
WHERE rating.meta_key='wpcr3_review_rating'
|
80
80
|
|
81
81
|
```
|
82
|
+
|
83
|
+
構造的に三つのメタ属性がセットなら、結合条件と抽出条件に明確に分けた方が、可読性は良くなります。
|
84
|
+
|
85
|
+
```SQL
|
86
|
+
|
87
|
+
SELECT round(AVG(rating.meta_value),1) AS review_avg, count(rating.post_id) AS review_cnt
|
88
|
+
|
89
|
+
FROM postmeta post
|
90
|
+
|
91
|
+
inner join postmeta name
|
92
|
+
|
93
|
+
on post.post_id=name.post_id
|
94
|
+
|
95
|
+
and post.meta_key='wpcr3_review_post' and name.meta_key='wpcr3_review_name'
|
96
|
+
|
97
|
+
inner join postmeta rating
|
98
|
+
|
99
|
+
on post.post_id=rating.post_id
|
100
|
+
|
101
|
+
and rating.meta_key='wpcr3_review_rating'
|
102
|
+
|
103
|
+
WHERE post.meta_value='10' and name.meta_value='editor'
|
104
|
+
|
105
|
+
```
|
3
追記
test
CHANGED
@@ -55,3 +55,27 @@
|
|
55
55
|
)
|
56
56
|
|
57
57
|
```
|
58
|
+
|
59
|
+
こっちの方が早いかも
|
60
|
+
|
61
|
+
```SQL
|
62
|
+
|
63
|
+
SELECT round(AVG(rating.meta_value),1) AS review_avg, count(rating.post_id) AS review_cnt
|
64
|
+
|
65
|
+
FROM postmeta rating
|
66
|
+
|
67
|
+
inner join postmeta post
|
68
|
+
|
69
|
+
on rating.post_id=post.post_id
|
70
|
+
|
71
|
+
and post.meta_key='wpcr3_review_post' and post.meta_value='10'
|
72
|
+
|
73
|
+
inner join postmeta name
|
74
|
+
|
75
|
+
on rating.post_id=name.post_id
|
76
|
+
|
77
|
+
and name.meta_key='wpcr3_review_name' and name.meta_value='editor'
|
78
|
+
|
79
|
+
WHERE rating.meta_key='wpcr3_review_rating'
|
80
|
+
|
81
|
+
```
|
2
推敲
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
SELECT 1 FROM postmeta
|
44
44
|
|
45
|
-
WHERE post_id=p.postid and meta_key='wpcr3_review_post' and meta_value='10'
|
45
|
+
WHERE post_id=p.post_id and meta_key='wpcr3_review_post' and meta_value='10'
|
46
46
|
|
47
47
|
)
|
48
48
|
|
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
SELECT 1 FROM postmeta
|
52
52
|
|
53
|
-
WHERE post_id=p.postid and meta_key='wpcr3_review_name' and meta_value='editor'
|
53
|
+
WHERE post_id=p.post_id and meta_key='wpcr3_review_name' and meta_value='editor'
|
54
54
|
|
55
55
|
)
|
56
56
|
|
1
推敲
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
()は正しく閉じられていますか?
|
2
2
|
|
3
|
-
SQL的には以下
|
3
|
+
SQL的には以下のはずです。
|
4
4
|
|
5
5
|
```SQL
|
6
6
|
|