--- title: "Querying" chapter: true weight: 206 --- ## QUERY EDITOR
- Grafana requires time-series data. As such, we’re going to modify our query to aggregate the average car purchases by the minute. We’re also going to create 2 parameters to see purchases between 2 particular time periods.
- Copy and paste the query below into the Query Editor. Do not **Run** it:
SELECT TIME_BUCKET(MINUTES(1), c._event_time) as timen, AVG(c.price_float) as avgprice,
FROM commons.CarPurchases as c
WHERE c._event_time > :startTime AND c._event_time < :stopTime
GROUP BY timen
ORDER BY timen
- To create a parameter, click on the **Parameters** tab and **Add Parameter**:
- Name the parameter **startTime**, set the type as **timestamp**, and format the value like this: **YYYY-MM-DDT00:00:00**. Use today’s date. If you’re attending the live workshop, enter this: ```2022-03-30T00:00:00```.
- Please repeat this step for **stopTime**. Use **timestamp** as the data type and set the value to 1 week after **startTime**, e.g., ```2022-04-06T00:00:00```.
- Now, **Run** the query. You should see something like this:
- The query lambda is how you’ll save your queries. If you need to reference a query later, you can look them up by clicking on Query Lambdas in the left nav.
Paste this this query below, highlight the query, and run it:
SELECT c.id, comp.companyName, count(*) as
purchases_from_car_company
FROM commons.CarPurchases AS c
JOIN commons.CarCompanies AS comp ON c.id =
TRY_CAST(comp.companyId AS int)
GROUP BY comp.companyName, c.id
ORDER BY count(*) DESC;
- Grafana requires time-series data, so we’ll modify this query like we did for _Analytical Query #1_. Just paste this query below in the Rockset Query Editor. _Do not **Run** it yet_:
SELECT
comp.companyName,
count(*) as purchases_from_car_company,
TIME_BUCKET(minutes(1), c._event_time) as timen
FROM
commons.CarPurchases AS c
JOIN commons.CarCompanies AS comp ON c.id = try_Cast(comp.companyId AS int)
WHERE
c._event_time > :startTime AND c._event_time < :stopTime
GROUP BY
comp.companyName,
timen
ORDER BY
count(*) DESC
;
- Create 2 parameters, startTime and stopTime like you did in _Analytical Query #1_. The data type will be **timestamp**. The value for **startTime** will be today’s date and the value for **stopTime** will be next week’s date, e.g. ```2022-03-30T00:00:00``` and ```2022-04-06T00:00:00```, respectively.
- Name your key rockset-aws-workshop-apikey. Make sure you choose the **admin role**. Finally, click on **Create API Key** on the bottom: