Select Statements
Select Statements
Select statements are used to output data. They are common for interactive development, reporting, and adhoc-pulls.
Select statements can also be used to define new concepts - a aliased concept in a select is usable throughout the rest of the script.
select_statement: where? "select"i select_list having? order_by? limit?
Where
A where clause can come before the select. The syntax is where followed by any boolean condition.
Where clause conditions apply before any aggregation. Where clause inputs do not need to be in the select list.
Select List
One or more comma-separated concept references or inline transformations bound to name. (Trailing commas are allowed.)
select
#an existing concept
user.id,
# creating a new concept
count(order.id)->user_orders,
# commented columns are resolved in the queyr but not output
--user.state,
;
Fields can be included - such as for filtering in having - without being output by commenting them with --. This is useful to include columns for filtering/sorting only.
Having
A having clause can come after the select list. The syntax is having followed by any boolean condition.
Having conditions apply after any aggregation. Having clause inputs must be in the select list.
Runtime Behavior
When executed in non-interactive mode, selects will be parsed but no execution will occur.
Example
import part as part;
WHERE part.supplier.nation.region.name = 'EUROPE'
SELECT
part.supplier.account_balance,
part.supplier.name,
part.supplier.nation.name,
part.id,
part.manufacturer,
part.supplier.id,
part.supplier.address,
part.supplier.phone,
part.supplier.comment,
--part.supply_cost,
min(part.supply_cost) by part.id as min_part_cost,
HAVING
part.supply_cost = min_part_cost
ORDER BY
part.id asc;
