human
Schema:
business (bid, business_id, name, full_address, city, latitude, longitude, review_count, is_open, rating, state)
category (id, business_id, category_name)
user (uid, user_id, name)
checkin (cid, business_id, count, day)
neighbourhood (id, business_id, neighbourhood_name)
review (rid, business_id, user_id, rating, text, year, month)
tip (tip_id, business_id, text, user_id, likes, year, month)
Please answer with SQL.
assistant
Sure, I understand.
human
Find all Bars reviewed by Patrick with at least 3 stars
assistant
SELECT t1.name FROM category AS t2 JOIN business AS t1 ON t2.business_id = t1.business_id JOIN review AS t3 ON t3.business_id = t1.business_id JOIN USER AS t4 ON t4.user_id = t3.user_id WHERE t1.rating >= 3 AND t2.category_name = 'Bars' AND t4.name = 'Patrick';
human
Find all reviews by Patrick with a rating above 4
assistant
SELECT t1.text FROM USER AS t2 JOIN review AS t1 ON t2.user_id = t1.user_id WHERE t1.rating > 4 AND t2.name = 'Patrick';
human
find the number of restaurant rated more than 3.5
assistant
SELECT COUNT ( DISTINCT t1.name ) FROM category AS t2 JOIN business AS t1 ON t2.business_id = t1.business_id WHERE t1.rating > 3.5 AND t2.category_name = 'restaurant';
human
What is the average rating of reviews written in year 2014 ?
assistant
SELECT AVG ( rating ) FROM review WHERE YEAR = 2014;
human
Find all users who reviewed restaurant ' Mesa Grill '
assistant
SELECT t4.name FROM category AS t2 JOIN business AS t1 ON t2.business_id = t1.business_id JOIN review AS t3 ON t3.business_id = t1.business_id JOIN USER AS t4 ON t4.user_id = t3.user_id WHERE t1.name = 'Mesa Grill' AND t2.category_name = 'restaurant';
human
Find users whose average review rating is below 3
assistant
SELECT t2.name FROM USER AS t2 JOIN review AS t1 ON t2.user_id = t1.user_id GROUP BY t2.name HAVING AVG ( t1.rating ) < 3 ;