I have an Apache combined log file that loads into Bigquery. Which has a schema that consists of resource, place_id, ip, start_time, end_time, device, status. I am trying to run a query that counts the number of resources and number of devices and groups them by resource and device.
Table:
resource | place_id | device | ip | status |
-----------------------------------------------------------------
/resource1 | 6750320008 | android | x.x.x.x | 200 |
/resource1 | 6750320100 | ipad | x.x.x.y | 200 |
/resource2 | 6750320008 | android | x.x.x.z | 200 |
Query:
SELECT resource, device
FROM (
Select
EXACT_COUNT_DISTINCT(resource) AS URL,
1 AS scalar,
FROM ([daily_logs.app_logs_data])
WHERE place_id = '6750320008' GROUP BY URL) AS datal
JOIN (
SELECT
COUNT(device) as DeviceCount,
1 AS scalar
FROM ([daily_logs.app_logs_data]) GROUP BY DeviceCount) AS y
ON datal.scalar=y.scalar
I receive this error: Error: Cannot group by an aggregate.
I am basically tyring to create two tables from the same table that count different items and then I want to join them together but have them be grouped in order like this:
URL | totalresourcecount | device | totaldevicecount
-----------------------------------------------------------------
/resource1 | 1 | android | 1
/resource1 | 1 | ipad | 1
/resource2 | 1 | android | 1
I have read through the google bigquery syntax help and looked at some examples but nothing has generated the desired result. Thanks in advance!
JOINis supposed to join the to queries and place_id is the filter. So I want to filter on place_id, count the resources, and then count the devices that used that resource. The output should show the resource, how many of those resources were counted, show the device that used that resource, and how many of those devices. - Prof. Falken