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

質問編集履歴

3

追記

2019/02/21 06:52

投稿

Chandler_Bing
Chandler_Bing

スコア673

title CHANGED
File without changes
body CHANGED
@@ -17,4 +17,82 @@
17
17
  FROM hotels_reviews GROUP BY hotel_i' at line 5
18
18
  ```
19
19
 
20
- となります。どこが間違えておりますでしょうか。
20
+ となります。どこが間違えておりますでしょうか。
21
+ 追記。以下がテーブルです。
22
+
23
+ ```SQL
24
+ -- phpMyAdmin SQL Dump
25
+ -- version 4.8.3
26
+ -- https://www.phpmyadmin.net/
27
+ --
28
+ -- Host: localhost:8889
29
+ -- Generation Time: Feb 21, 2019 at 06:49 AM
30
+ -- Server version: 5.7.23
31
+ -- PHP Version: 7.2.8
32
+
33
+ SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
34
+ SET time_zone = "+00:00";
35
+
36
+ --
37
+ -- Database: `BookingSite`
38
+ --
39
+
40
+ -- --------------------------------------------------------
41
+
42
+ --
43
+ -- Table structure for table `hotels_reviews`
44
+ --
45
+
46
+ CREATE TABLE `hotels_reviews` (
47
+ `hotels_reviews_id` int(11) NOT NULL,
48
+ `hotel_id` int(11) NOT NULL,
49
+ `country_code` enum('JPN','PHL') DEFAULT NULL,
50
+ `user_name` varchar(100) NOT NULL,
51
+ `user_country` enum('JPN','PHL') DEFAULT NULL,
52
+ `content` text NOT NULL,
53
+ `length` int(11) NOT NULL,
54
+ `rating` enum('1','2','3','4','5') DEFAULT NULL
55
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
56
+
57
+ --
58
+ -- Dumping data for table `hotels_reviews`
59
+ --
60
+
61
+ INSERT INTO `hotels_reviews` (`hotels_reviews_id`, `hotel_id`, `country_code`, `user_name`, `user_country`, `content`, `length`, `rating`) VALUES
62
+ (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'),
63
+ (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'),
64
+ (9, 3, 'PHL', 'YutaNakai', 'JPN', 'とても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。とても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。\r\nとても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。', 8, '5'),
65
+ (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'),
66
+ (15, 3, 'PHL', '井上', 'JPN', 'とても素晴らしかったです。また行きます!', 2, '5'),
67
+ (16, 3, 'PHL', 'ChinMu', 'PHL', 'Everything was good but the fact that they gave us the uncorrect key twice.', 3, '4'),
68
+ (17, 1, 'PHL', 'みっちー', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '3'),
69
+ (18, 1, 'PHL', 'NOHARA', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '3'),
70
+ (19, 1, 'PHL', 'Monica', 'PHL', 'That was too dirty although cheap.......', 2, '2'),
71
+ (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'),
72
+ (21, 2, 'PHL', 'Narita', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '4'),
73
+ (22, 2, 'PHL', 'shinohara', 'JPN', '特にこれといって悪いところはなかったので、次も利用したいと思います。', 3, '4'),
74
+ (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'),
75
+ (24, 2, 'PHL', 'Tom', 'PHL', 'Normal......................', 5, '3');
76
+
77
+ --
78
+ -- Indexes for dumped tables
79
+ --
80
+
81
+ --
82
+ -- Indexes for table `hotels_reviews`
83
+ --
84
+ ALTER TABLE `hotels_reviews`
85
+ ADD PRIMARY KEY (`hotels_reviews_id`),
86
+ ADD UNIQUE KEY `hotel_id` (`hotel_id`,`country_code`,`user_name`);
87
+
88
+ --
89
+ -- AUTO_INCREMENT for dumped tables
90
+ --
91
+
92
+ --
93
+ -- AUTO_INCREMENT for table `hotels_reviews`
94
+ --
95
+ ALTER TABLE `hotels_reviews`
96
+ MODIFY `hotels_reviews_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
97
+
98
+ ```

2

誤字

2019/02/21 06:52

投稿

Chandler_Bing
Chandler_Bing

スコア673

title CHANGED
File without changes
body CHANGED
@@ -1,10 +1,11 @@
1
+ 現在のコードとエラーです
1
2
  ``` SQL
2
- SELECT hotel_id, AVG(rating) AS rate
3
+ SELECT hotel_id, AVG(rating) AS rate,
3
4
  CASE WHEN rate > 4.5 THEN '非常に良い'
4
5
  WHEN rate > 3 THEN '普通'
5
6
  WHEN rate <= 3 THEN '平均未満'
6
- ELSE rate '評価なし'
7
+ ELSE rate'評価なし'
7
- END AS ratingresult
8
+ END AS 'ratingresult'
8
9
  FROM hotels_reviews GROUP BY hotel_id
9
10
  ```
10
11
 
@@ -12,9 +13,8 @@
12
13
 
13
14
  ```error
14
15
  #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 ''評価なし'
15
- END AS 'result'
16
+ END AS 'ratingresult'
16
- FROM hotels_reviews
17
- GROUP BY hotel_id' at line 5
17
+ FROM hotels_reviews GROUP BY hotel_i' at line 5
18
18
  ```
19
19
 
20
20
  となります。どこが間違えておりますでしょうか。

1

aaaaa

2019/02/16 08:25

投稿

Chandler_Bing
Chandler_Bing

スコア673

title CHANGED
File without changes
body CHANGED
@@ -1,12 +1,11 @@
1
1
  ``` SQL
2
- SELECT hotel_id, AVG(rating) AS rate,
2
+ SELECT hotel_id, AVG(rating) AS rate
3
- CASE WHEN rate < 4.5 THEN '非常に良い'
3
+ CASE WHEN rate > 4.5 THEN '非常に良い'
4
- WHEN rate < 3 THEN '普通'
4
+ WHEN rate > 3 THEN '普通'
5
- WHEN rate >= 3 THEN '平均未満'
5
+ WHEN rate <= 3 THEN '平均未満'
6
6
  ELSE rate '評価なし'
7
- END AS 'result'
7
+ END AS ratingresult
8
- FROM hotels_reviews
8
+ FROM hotels_reviews GROUP BY hotel_id
9
- GROUP BY hotel_id
10
9
  ```
11
10
 
12
11
  これを実行すると