質問編集履歴

3

追記

2019/02/21 06:52

投稿

Chandler_Bing
Chandler_Bing

スコア673

test CHANGED
File without changes
test CHANGED
@@ -37,3 +37,159 @@
37
37
 
38
38
 
39
39
  となります。どこが間違えておりますでしょうか。
40
+
41
+ 追記。以下がテーブルです。
42
+
43
+
44
+
45
+ ```SQL
46
+
47
+ -- phpMyAdmin SQL Dump
48
+
49
+ -- version 4.8.3
50
+
51
+ -- https://www.phpmyadmin.net/
52
+
53
+ --
54
+
55
+ -- Host: localhost:8889
56
+
57
+ -- Generation Time: Feb 21, 2019 at 06:49 AM
58
+
59
+ -- Server version: 5.7.23
60
+
61
+ -- PHP Version: 7.2.8
62
+
63
+
64
+
65
+ SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
66
+
67
+ SET time_zone = "+00:00";
68
+
69
+
70
+
71
+ --
72
+
73
+ -- Database: `BookingSite`
74
+
75
+ --
76
+
77
+
78
+
79
+ -- --------------------------------------------------------
80
+
81
+
82
+
83
+ --
84
+
85
+ -- Table structure for table `hotels_reviews`
86
+
87
+ --
88
+
89
+
90
+
91
+ CREATE TABLE `hotels_reviews` (
92
+
93
+ `hotels_reviews_id` int(11) NOT NULL,
94
+
95
+ `hotel_id` int(11) NOT NULL,
96
+
97
+ `country_code` enum('JPN','PHL') DEFAULT NULL,
98
+
99
+ `user_name` varchar(100) NOT NULL,
100
+
101
+ `user_country` enum('JPN','PHL') DEFAULT NULL,
102
+
103
+ `content` text NOT NULL,
104
+
105
+ `length` int(11) NOT NULL,
106
+
107
+ `rating` enum('1','2','3','4','5') DEFAULT NULL
108
+
109
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
110
+
111
+
112
+
113
+ --
114
+
115
+ -- Dumping data for table `hotels_reviews`
116
+
117
+ --
118
+
119
+
120
+
121
+ INSERT INTO `hotels_reviews` (`hotels_reviews_id`, `hotel_id`, `country_code`, `user_name`, `user_country`, `content`, `length`, `rating`) VALUES
122
+
123
+ (7, 3, 'PHL', 'Chandler', 'PHL', 'This is by far the best stay that I have ever had. People are very nice Which if there is next time,\r\nmakes me want to book the hoel again.This is by far the best stay that I have ever had. People are very nice Which if there is next time,\r\nmakes me want to book the hoel again.', 3, '5'),
124
+
125
+ (8, 3, 'PHL', 'ハマショー', 'JPN', 'This is by far the best stay that I have ever had. People are very nice Which if there is next time,\r\nmakes me want to book the hoel again.This is by far the best stay that I have ever had. People are very nice Which if there is next time,\r\nmakes me want to book the hoel again.', 4, '5'),
126
+
127
+ (9, 3, 'PHL', 'YutaNakai', 'JPN', 'とても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。とても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。\r\nとても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。', 8, '5'),
128
+
129
+ (14, 3, 'PHL', 'Joye', 'JPN', 'Everything was so good that there is nothing that I can complain about even if I had to. Especially, one of the receptionist was amazing.\r\nThe way she takes care of customer,she speaks and stuff.Thank you for delightful stay.Everything was so good that there is nothing that I can complain about even if I had to. Especially, one of the receptionist was amazing.\r\nThe way she takes care of customer,she speaks and stuff.Thank you for delightful stay.', 2, '5'),
130
+
131
+ (15, 3, 'PHL', '井上', 'JPN', 'とても素晴らしかったです。また行きます!', 2, '5'),
132
+
133
+ (16, 3, 'PHL', 'ChinMu', 'PHL', 'Everything was good but the fact that they gave us the uncorrect key twice.', 3, '4'),
134
+
135
+ (17, 1, 'PHL', 'みっちー', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '3'),
136
+
137
+ (18, 1, 'PHL', 'NOHARA', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '3'),
138
+
139
+ (19, 1, 'PHL', 'Monica', 'PHL', 'That was too dirty although cheap.......', 2, '2'),
140
+
141
+ (20, 2, 'PHL', 'Monica', 'PHL', 'Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.', 1, '4'),
142
+
143
+ (21, 2, 'PHL', 'Narita', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '4'),
144
+
145
+ (22, 2, 'PHL', 'shinohara', 'JPN', '特にこれといって悪いところはなかったので、次も利用したいと思います。', 3, '4'),
146
+
147
+ (23, 2, 'PHL', 'Ross', 'PHL', 'Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. \r\nI can go there again.Nothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.\r\nNothing so bad so that was okay. I can go there again.Nothing so bad so that was okay. I can go there again.', 2, '4'),
148
+
149
+ (24, 2, 'PHL', 'Tom', 'PHL', 'Normal......................', 5, '3');
150
+
151
+
152
+
153
+ --
154
+
155
+ -- Indexes for dumped tables
156
+
157
+ --
158
+
159
+
160
+
161
+ --
162
+
163
+ -- Indexes for table `hotels_reviews`
164
+
165
+ --
166
+
167
+ ALTER TABLE `hotels_reviews`
168
+
169
+ ADD PRIMARY KEY (`hotels_reviews_id`),
170
+
171
+ ADD UNIQUE KEY `hotel_id` (`hotel_id`,`country_code`,`user_name`);
172
+
173
+
174
+
175
+ --
176
+
177
+ -- AUTO_INCREMENT for dumped tables
178
+
179
+ --
180
+
181
+
182
+
183
+ --
184
+
185
+ -- AUTO_INCREMENT for table `hotels_reviews`
186
+
187
+ --
188
+
189
+ ALTER TABLE `hotels_reviews`
190
+
191
+ MODIFY `hotels_reviews_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
192
+
193
+
194
+
195
+ ```

2

誤字

2019/02/21 06:52

投稿

Chandler_Bing
Chandler_Bing

スコア673

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,8 @@
1
+ 現在のコードとエラーです
2
+
1
3
  ``` SQL
2
4
 
3
- SELECT hotel_id, AVG(rating) AS rate
5
+ SELECT hotel_id, AVG(rating) AS rate,
4
6
 
5
7
  CASE WHEN rate > 4.5 THEN '非常に良い'
6
8
 
@@ -8,9 +10,9 @@
8
10
 
9
11
  WHEN rate <= 3 THEN '平均未満'
10
12
 
11
- ELSE rate '評価なし'
13
+ ELSE rate'評価なし'
12
14
 
13
- END AS ratingresult
15
+ END AS 'ratingresult'
14
16
 
15
17
  FROM hotels_reviews GROUP BY hotel_id
16
18
 
@@ -26,11 +28,9 @@
26
28
 
27
29
  #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''評価なし'
28
30
 
29
- END AS 'result'
31
+ END AS 'ratingresult'
30
32
 
31
- FROM hotels_reviews
32
-
33
- GROUP BY hotel_id' at line 5
33
+ FROM hotels_reviews GROUP BY hotel_i' at line 5
34
34
 
35
35
  ```
36
36
 

1

aaaaa

2019/02/16 08:25

投稿

Chandler_Bing
Chandler_Bing

スコア673

test CHANGED
File without changes
test CHANGED
@@ -1,20 +1,18 @@
1
1
  ``` SQL
2
2
 
3
- SELECT hotel_id, AVG(rating) AS rate,
3
+ SELECT hotel_id, AVG(rating) AS rate
4
4
 
5
- CASE WHEN rate < 4.5 THEN '非常に良い'
5
+ CASE WHEN rate > 4.5 THEN '非常に良い'
6
6
 
7
- WHEN rate < 3 THEN '普通'
7
+ WHEN rate > 3 THEN '普通'
8
8
 
9
- WHEN rate >= 3 THEN '平均未満'
9
+ WHEN rate <= 3 THEN '平均未満'
10
10
 
11
11
  ELSE rate '評価なし'
12
12
 
13
- END AS 'result'
13
+ END AS ratingresult
14
14
 
15
- FROM hotels_reviews
15
+ FROM hotels_reviews GROUP BY hotel_id
16
-
17
- GROUP BY hotel_id
18
16
 
19
17
  ```
20
18