1
0
mirror of https://github.com/balkian/gists.git synced 2024-11-01 08:01:44 +00:00
gists/gistfile1.sql

12 lines
825 B
MySQL
Raw Normal View History

2015-04-14 16:10:11 +00:00
SELECT count(*) AS C, payload->'retweeted_status'->>'id' AS cat, payload->'retweeted_status'->>'text' AS Tweet FROM messages WHERE jsonb_typeof(payload) = 'object' and payload->>'text' not like '%http%' GROUP BY cat, Tweet ORDER BY C DESC;
# Works just fine
SELECT count(*) AS C, payload->'retweeted_status'->>'id' AS cat, payload->'retweeted_status'->>'text' AS Tweet, payload->'retweeted_status'->'User'->>'screen_name' AS User FROM messages WHERE jsonb_typeof(payload) = 'object' and payload->>'text' not like '%http%' GROUP BY cat, Tweet, User ORDER BY C DESC;
# Doesn't work
# ------------
# ERROR: column "messages.payload" must appear in the GROUP BY clause or be used in an aggregate function
# LINE 1: ...t, payload->'retweeted_status'->>'text' AS Tweet, payload->'...
#Problem: User was the name of a column :)