Greater and Less than QBE Operators
Learn to use QBE operators _gt, _gte,
_lt and _lte to filter specific data from the car
racing dataset through simple examples.
Consider a scenario where you would like to fetch the details of drivers who
scored more than 360 points. You can use the QBE operator, '_gt'
to achieve this:
Example 3-5 _gt Operator
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
driver (
check: {
points: {_gt: 360}
}
)
{
id: driver_id
name
points
}
');
This code would access the table driver, checks for those
drivers whose points are greater than
360, and retrieves their id, name and
points:
DATA
--------------------------------------------------------------------------------
{
"id" : 102,
"name" : "Oscar Piastri",
"points" : 384
}
{
"id" : 105,
"name" : "Max Verstappen",
"points" : 456
}
2 rows selected.Or you may want to fetch details of all teams. Further, you would like to find the drivers who scored less than or equal to 100 points in each team. The example uses the check clause on a nested table:
Example 3-6 _lte Operator
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
team {
id: team_id
name
points
underPerformingDrivers: driver (
check: {
points: {_lte: 100}
}
)
{
driverName: name
points
}
}
');
The above example would fetch the team's
id, name and points. Then makes a
list of under performing drivers in the team who have scored less than or equal to 100
points and displays their name and points with the
team's data:
DATA
--------------------------------------------------------------------
{
"id" : 301,
"name" : "McLaren Mercedes",
"points" : 666,
"underPerformingDrivers" :
[
]
}
................................
................................
{
"id" : 309,
"name" : "Williams Mercedes",
"points" : 17,
"underPerformingDrivers" :
[
{
"driverName" : "Alexander Albon",
"points" : 12
},
{
"driverName" : "Logan Sargeant",
"points" : 5
}
]
}
{
"id" : 310,
"name" : "Kick Sauber Ferrari",
"points" : 4,
"underPerformingDrivers" :
[
{
"driverName" : "Valtteri Bottas",
"points" : 3
},
{
"driverName" : "Zhou Guanyu",
"points" : 1
}
]
}
10 rows selected.