---
title: Final challenge
summary: Three rounds without new syntax: a report query, a grouped survey and a spatial selection, each one a statement you would write at work.
order: 100
terms: [bql, qid, pset]
see-also: [tutorials/bql/export-to-ifc, reference/bql/cheatsheet, how-to/query/run-a-bql-query]
---

# Final challenge

No new constructs on this page. Each round is a question someone actually asks about a model, and the answer needs several of the clauses you have learned at once. The hints are shorter than before on purpose; the [[bql:cheatsheet]] is the page to keep open next to this one.

The clause order never changes, and remembering it is half of writing a long statement:

```text {#skeleton}
GET <feature> [UNIT <unit>] [AS <alias>], ...
WHERE <condition>
GROUP BY <feature>, ...
ORDER BY <feature> [ASC|DESC], ...
LIMIT <n>
OFFSET <n>
USING <DIMENSION>_UNIT = <unit> ...
```

## Your turn

```lesson {#lesson-1}
goal: A wall report — the five external walls with the largest net side area, with their name, the storey they are on and that area in square metres, largest first.
show: table
check: sequence
starter: |
  GET qid, attribute.Name WHERE type = IFCWALL
hints: |
  - Three columns besides qid: the name, the storey's name, the quantity NetSideArea.
  - "External" is the property IsExternal; the set wildcard saves you looking the set up.
  - ORDER BY … DESC on the same quantity, then LIMIT 5.
  - USING AREA_UNIT = m2 converts the area of the whole statement.
solution: |
  GET qid, attribute.Name, buildingStorey.attribute.Name, quantity.*.NetSideArea
  WHERE type = IFCWALL AND property.*.IsExternal = true
  ORDER BY quantity.*.NetSideArea DESC
  LIMIT 5
  USING AREA_UNIT = m2
accept: |
  - GET qid, attribute.Name, buildingStorey.attribute.Name, quantity.*.NetSideArea AS Area WHERE type = IFCWALL AND property.*.IsExternal = true ORDER BY quantity.*.NetSideArea DESC LIMIT 5 USING AREA_UNIT = m2
```

```lesson {#lesson-2}
goal: A survey of the doors — how many doors each storey has, and the total area of their openings, per storey.
show: json
check: rows
starter: |
  GET buildingStorey.attribute.Name, COUNT(qid) WHERE type = IFCDOOR GROUP BY buildingStorey.attribute.Name
hints: |
  - The count is already there; the second aggregate is a SUM over a quantity of the door.
  - The quantity of a door opening is called Area in the demo model's BaseQuantities.
  - An aggregate cannot carry UNIT; convert the statement with USING instead.
solution: |
  GET buildingStorey.attribute.Name, COUNT(qid), SUM(quantity.*.Area)
  WHERE type = IFCDOOR
  GROUP BY buildingStorey.attribute.Name
  USING AREA_UNIT = m2
accept: |
  - GET buildingStorey.attribute.Name AS Storey, COUNT(qid) AS Doors, SUM(quantity.*.Area) AS OpeningArea WHERE type = IFCDOOR GROUP BY buildingStorey.attribute.Name USING AREA_UNIT = m2
```

```lesson {#lesson-3}
goal: The rooms of the ground floor ("00 begane grond") whose long name says they are a room ("kamer"), in the viewer, with their long name.
show: viewer
check: objects
starter: |
  GET qid, attribute.LongName WHERE type = IFCSPACE
hints: |
  - Three conditions: the class, the storey, and the word in the long name.
  - The storey is a relation: buildingStorey.attribute.Name.
  - CONTAINS matches a word anywhere in the value, and ignores case.
solution: |
  GET qid, attribute.LongName
  WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "00 begane grond" AND attribute.LongName CONTAINS "kamer"
accept: |
  - GET qid, attribute.LongName WHERE type = IFCSPACE AND attribute.LongName CONTAINS "kamer" AND buildingStorey.calculated.property.level = 0
```

Eleven rooms, coloured in the model. Try the same query with the first floor and you get nothing: up there the modeller named the spaces `instal. ruimte`, `hal` and `berging`, which is the sort of thing a survey (lesson 8) tells you before a check depends on it.

## You have finished the course

You can select objects, filter them on anything the model carries, follow the graph around them, summarise them, control the units, use what BIM.works computes, ask geometric questions and take the result out as a file.

From here:

- The [[bql:cheatsheet]] — every construct on one page, one line each.
- [[page:how-to/query/run-a-bql-query]] — running queries from JavaScript, Java, .NET, PHP and the API.
- [[page:reference/bql]] — the language clause by clause, when a construct needs its exact rules.
- The [Build a model viewer](../javascript-viewer/index.md) course — query results in a viewer of your own.
- [[bql:spatial-and-advanced]] — the constructs this course only mentioned: clashes and containment, clearance, paths and graphs, walkable routes, usable area, virtual shapes, full-text search.

The other query languages are learned the same way: [[page:reference/bcl|BCL]] checks a model against rules, [[page:reference/bvl|BVL]] colours it, [[page:reference/bul|BUL]] changes it, and all of them use the BQL selections you have just learned.
