現在のコードとエラーです
SQL
1SELECT hotel_id, AVG(rating) AS rate, 2CASE WHEN rate > 4.5 THEN '非常に良い' 3 WHEN rate > 3 THEN '普通' 4 WHEN rate <= 3 THEN '平均未満' 5 ELSE rate'評価なし' 6 END AS 'ratingresult' 7FROM hotels_reviews GROUP BY hotel_id
これを実行すると
error
1#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 ''評価なし' 2 END AS 'ratingresult' 3FROM hotels_reviews GROUP BY hotel_i' at line 5
となります。どこが間違えておりますでしょうか。
追記。以下がテーブルです。
SQL
1-- phpMyAdmin SQL Dump 2-- version 4.8.3 3-- https://www.phpmyadmin.net/ 4-- 5-- Host: localhost:8889 6-- Generation Time: Feb 21, 2019 at 06:49 AM 7-- Server version: 5.7.23 8-- PHP Version: 7.2.8 9 10SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11SET time_zone = "+00:00"; 12 13-- 14-- Database: `BookingSite` 15-- 16 17-- -------------------------------------------------------- 18 19-- 20-- Table structure for table `hotels_reviews` 21-- 22 23CREATE TABLE `hotels_reviews` ( 24 `hotels_reviews_id` int(11) NOT NULL, 25 `hotel_id` int(11) NOT NULL, 26 `country_code` enum('JPN','PHL') DEFAULT NULL, 27 `user_name` varchar(100) NOT NULL, 28 `user_country` enum('JPN','PHL') DEFAULT NULL, 29 `content` text NOT NULL, 30 `length` int(11) NOT NULL, 31 `rating` enum('1','2','3','4','5') DEFAULT NULL 32) ENGINE=InnoDB DEFAULT CHARSET=utf8; 33 34-- 35-- Dumping data for table `hotels_reviews` 36-- 37 38INSERT INTO `hotels_reviews` (`hotels_reviews_id`, `hotel_id`, `country_code`, `user_name`, `user_country`, `content`, `length`, `rating`) VALUES 39(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'), 40(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'), 41(9, 3, 'PHL', 'YutaNakai', 'JPN', 'とても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。とても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。\r\nとても素晴らしい滞在でした。皆さんとても親切でまた行きたと思いました。他の方にも体験して欲しいです。', 8, '5'), 42(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'), 43(15, 3, 'PHL', '井上', 'JPN', 'とても素晴らしかったです。また行きます!', 2, '5'), 44(16, 3, 'PHL', 'ChinMu', 'PHL', 'Everything was good but the fact that they gave us the uncorrect key twice.', 3, '4'), 45(17, 1, 'PHL', 'みっちー', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '3'), 46(18, 1, 'PHL', 'NOHARA', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '3'), 47(19, 1, 'PHL', 'Monica', 'PHL', 'That was too dirty although cheap.......', 2, '2'), 48(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'), 49(21, 2, 'PHL', 'Narita', 'JPN', '普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。\r\n普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。普通です。', 2, '4'), 50(22, 2, 'PHL', 'shinohara', 'JPN', '特にこれといって悪いところはなかったので、次も利用したいと思います。', 3, '4'), 51(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'), 52(24, 2, 'PHL', 'Tom', 'PHL', 'Normal......................', 5, '3'); 53 54-- 55-- Indexes for dumped tables 56-- 57 58-- 59-- Indexes for table `hotels_reviews` 60-- 61ALTER TABLE `hotels_reviews` 62 ADD PRIMARY KEY (`hotels_reviews_id`), 63 ADD UNIQUE KEY `hotel_id` (`hotel_id`,`country_code`,`user_name`); 64 65-- 66-- AUTO_INCREMENT for dumped tables 67-- 68 69-- 70-- AUTO_INCREMENT for table `hotels_reviews` 71-- 72ALTER TABLE `hotels_reviews` 73 MODIFY `hotels_reviews_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25; 74
何を目的としたコードなのか書かないと的確な回答は得られません。
で、いつになったらエラー読むの?
別の回答に書きましたよね。
https://qiita.com/cannorin/items/eb062aae88bfe2ad6fe5
これ読んで理解して実践できるようになるまで質問しないくらいの気持ちでやってくれって。
何度も言ってます。
プログラムは書いた通りに動くもの。あなたは「どこが間違えてる?」と言えるほど思うように動かせる実力は皆無です。
基礎の基礎の基礎からやり直してください。
「まだ回答を求めています」と書いている割に何も自分でやってないので何も進んでません。
依頼する前にやることがあるでしょう。
回答6件
あなたの回答
tips
プレビュー