YAML
declare:
eql:
operator: =
left: $1
right: $2
get_field:
field: $1
get_table:
type: left_join
from: $1
on:
apply: ["eql", $2, $3]
order_by:
field: $1
by: $2
having_cond:
operator: ">"
left: AVG(ISNULL(DATEDIFF(SECOND, $1, $2),0))
right: (SELECT AVG(DATEDIFF(SECOND, $1, $2)) FROM $3)
main:
select:
- apply: ["get_field", "country.country_name_eng"]
from: country
join:
- apply: ["get_table", "city", "city.country_id", "country.id"]
- apply: ["get_table", "customer", "city.id", "customer.city_id"]
- apply: ["get_table", "call", "customer.id", "call.customer_id"]
group:
- country.id
- country.country_name_eng
order:
- apply: ["order_by", "calls", "desc"]
- apply: ["order_by", "country_id", "asc"]
having:
- apply: ["having_cond", "call.start_time", "call.end_time", "call"]
SQL