[
{
"type": "Query",
"text": "select * from projects",
"start": 0,
"end": 22,
"fields": [
{
"type": "Clause::Select",
"field": "select",
"text": "select *",
"start": 0,
"end": 8,
"fields": [
{
"type": "Token[]",
"field": "items",
"text": "*",
"start": 7,
"end": 8,
"items": [
{
"type": "Token::Wildcard",
"text": "*",
"start": 7,
"end": 8
}
]
}
]
},
{
"type": "Clause::From",
"field": "from",
"text": "from projects",
"start": 9,
"end": 22,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "projects",
"start": 14,
"end": 22
}
]
}
]
},
{
"type": "Query",
"text": "SELECT distinct customers.name, orders.order_date, orders.total_amount\nFROM customers\n INNER JOIN orders ON customers.id = orders.customer_id\nWHERE orders.total_amount > 100\n AND orders.status = 'Completed'\nORDER BY orders.order_date ASC\nLIMIT 20",
"start": 25,
"end": 273,
"fields": [
{
"type": "Clause::Select",
"field": "select",
"text": "SELECT distinct customers.name, orders.order_date, orders.total_amount",
"start": 25,
"end": 95,
"fields": [
{
"type": "Keyword::SelectQuantifier::Distinct",
"field": "quantifier",
"text": "distinct",
"start": 32,
"end": 40
},
{
"type": "Token[]",
"field": "items",
"text": "customers.name, orders.order_date, orders.total_amount",
"start": 41,
"end": 95,
"items": [
{
"type": "Token::ColumnReference",
"text": "customers.name",
"start": 41,
"end": 55,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "customers",
"start": 41,
"end": 50
},
{
"type": "Token::Identifier",
"field": "column",
"text": "name",
"start": 51,
"end": 55
}
]
},
{
"type": "Token::ColumnReference",
"text": "orders.order_date",
"start": 57,
"end": 74,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 57,
"end": 63
},
{
"type": "Token::Identifier",
"field": "column",
"text": "order_date",
"start": 64,
"end": 74
}
]
},
{
"type": "Token::ColumnReference",
"text": "orders.total_amount",
"start": 76,
"end": 95,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 76,
"end": 82
},
{
"type": "Token::Identifier",
"field": "column",
"text": "total_amount",
"start": 83,
"end": 95
}
]
}
]
}
]
},
{
"type": "Clause::From",
"field": "from",
"text": "FROM customers",
"start": 96,
"end": 110,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "customers",
"start": 101,
"end": 110
}
]
},
{
"type": "Clause::Join",
"field": "join",
"text": "INNER JOIN orders ON customers.id = orders.customer_id",
"start": 113,
"end": 167,
"fields": [
{
"type": "Keyword::JoinType::Inner",
"field": "joinType",
"text": "INNER",
"start": 113,
"end": 118
},
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 124,
"end": 130
},
{
"type": "Condition::Comparison",
"field": "condition",
"text": "customers.id = orders.customer_id",
"start": 134,
"end": 167,
"fields": [
{
"type": "Token::ColumnReference",
"field": "left",
"text": "customers.id",
"start": 134,
"end": 146,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "customers",
"start": 134,
"end": 143
},
{
"type": "Token::Identifier",
"field": "column",
"text": "id",
"start": 144,
"end": 146
}
]
},
{
"type": "ComparisonOperator::Equal",
"field": "operator",
"text": "=",
"start": 147,
"end": 148
},
{
"type": "Token::ColumnReference",
"field": "right",
"text": "orders.customer_id",
"start": 149,
"end": 167,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 149,
"end": 155
},
{
"type": "Token::Identifier",
"field": "column",
"text": "customer_id",
"start": 156,
"end": 167
}
]
}
]
}
]
},
{
"type": "Clause::Where",
"field": "where",
"text": "WHERE orders.total_amount > 100\n AND orders.status = 'Completed'",
"start": 168,
"end": 233,
"fields": [
{
"type": "Condition::And",
"field": "condition",
"text": "orders.total_amount > 100\n AND orders.status = 'Completed'",
"start": 174,
"end": 233,
"fields": [
{
"type": "Condition[]",
"field": "conditions",
"text": "orders.total_amount > 100\n AND orders.status = 'Completed'",
"start": 174,
"end": 233,
"items": [
{
"type": "Condition::Comparison",
"text": "orders.total_amount > 100",
"start": 174,
"end": 199,
"fields": [
{
"type": "Token::ColumnReference",
"field": "left",
"text": "orders.total_amount",
"start": 174,
"end": 193,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 174,
"end": 180
},
{
"type": "Token::Identifier",
"field": "column",
"text": "total_amount",
"start": 181,
"end": 193
}
]
},
{
"type": "ComparisonOperator::GreaterThan",
"field": "operator",
"text": ">",
"start": 194,
"end": 195
},
{
"type": "Token::NumberLiteral",
"field": "right",
"text": "100",
"start": 196,
"end": 199
}
]
},
{
"type": "Condition::Comparison",
"text": "orders.status = 'Completed'",
"start": 206,
"end": 233,
"fields": [
{
"type": "Token::ColumnReference",
"field": "left",
"text": "orders.status",
"start": 206,
"end": 219,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 206,
"end": 212
},
{
"type": "Token::Identifier",
"field": "column",
"text": "status",
"start": 213,
"end": 219
}
]
},
{
"type": "ComparisonOperator::Equal",
"field": "operator",
"text": "=",
"start": 220,
"end": 221
},
{
"type": "Token::StringLiteral",
"field": "right",
"text": "'Completed'",
"start": 222,
"end": 233
}
]
}
]
}
]
}
]
},
{
"type": "Clause::OrderBy",
"field": "orderBy",
"text": "ORDER BY orders.order_date ASC",
"start": 234,
"end": 264,
"fields": [
{
"type": "SortItem[]",
"field": "sortItems",
"text": "orders.order_date ASC",
"start": 243,
"end": 264,
"items": [
{
"type": "SortItem",
"text": "orders.order_date ASC",
"start": 243,
"end": 264,
"fields": [
{
"type": "Token::ColumnReference",
"field": "expression",
"text": "orders.order_date",
"start": 243,
"end": 260,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "orders",
"start": 243,
"end": 249
},
{
"type": "Token::Identifier",
"field": "column",
"text": "order_date",
"start": 250,
"end": 260
}
]
},
{
"type": "Keyword::SortDirection::Ascending",
"field": "direction",
"text": "ASC",
"start": 261,
"end": 264
}
]
}
]
}
]
},
{
"type": "Clause::Limit",
"field": "limit",
"text": "LIMIT 20",
"start": 265,
"end": 273,
"fields": [
{
"type": "Token::NumberLiteral",
"field": "count",
"text": "20",
"start": 271,
"end": 273
}
]
}
]
},
{
"type": "Query",
"text": "select name, age, count(*) as total\nfrom users\nwhere age >= 18\ngroup by name, age\nhaving count(*) > 1\norder by age desc\nlimit 10",
"start": 276,
"end": 404,
"fields": [
{
"type": "Clause::Select",
"field": "select",
"text": "select name, age, count(*) as total",
"start": 276,
"end": 311,
"fields": [
{
"type": "Token[]",
"field": "items",
"text": "name, age, count(*) as total",
"start": 283,
"end": 311,
"items": [
{
"type": "Token::Identifier",
"text": "name",
"start": 283,
"end": 287
},
{
"type": "Token::Identifier",
"text": "age",
"start": 289,
"end": 292
},
{
"type": "Token::AliasedExpression",
"text": "count(*) as total",
"start": 294,
"end": 311,
"fields": [
{
"type": "Token::FunctionCall",
"field": "value",
"text": "count(*)",
"start": 294,
"end": 302,
"fields": [
{
"type": "Token::Identifier",
"field": "name",
"text": "count",
"start": 294,
"end": 299
},
{
"type": "Token[]",
"field": "arguments",
"text": "*",
"start": 300,
"end": 301,
"items": [
{
"type": "Token::Wildcard",
"text": "*",
"start": 300,
"end": 301
}
]
}
]
},
{
"type": "Token::Identifier",
"field": "alias",
"text": "total",
"start": 306,
"end": 311
}
]
}
]
}
]
},
{
"type": "Clause::From",
"field": "from",
"text": "from users",
"start": 312,
"end": 322,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "users",
"start": 317,
"end": 322
}
]
},
{
"type": "Clause::Where",
"field": "where",
"text": "where age >= 18",
"start": 323,
"end": 338,
"fields": [
{
"type": "Condition::Comparison",
"field": "condition",
"text": "age >= 18",
"start": 329,
"end": 338,
"fields": [
{
"type": "Token::Identifier",
"field": "left",
"text": "age",
"start": 329,
"end": 332
},
{
"type": "ComparisonOperator::GreaterOrEqual",
"field": "operator",
"text": ">=",
"start": 333,
"end": 335
},
{
"type": "Token::NumberLiteral",
"field": "right",
"text": "18",
"start": 336,
"end": 338
}
]
}
]
},
{
"type": "Clause::GroupBy",
"field": "groupBy",
"text": "group by name, age",
"start": 339,
"end": 357,
"fields": [
{
"type": "Token[]",
"field": "expressions",
"text": "name, age",
"start": 348,
"end": 357,
"items": [
{
"type": "Token::Identifier",
"text": "name",
"start": 348,
"end": 352
},
{
"type": "Token::Identifier",
"text": "age",
"start": 354,
"end": 357
}
]
}
]
},
{
"type": "Clause::Having",
"field": "having",
"text": "having count(*) > 1",
"start": 358,
"end": 377,
"fields": [
{
"type": "Condition::Comparison",
"field": "condition",
"text": "count(*) > 1",
"start": 365,
"end": 377,
"fields": [
{
"type": "Token::FunctionCall",
"field": "left",
"text": "count(*)",
"start": 365,
"end": 373,
"fields": [
{
"type": "Token::Identifier",
"field": "name",
"text": "count",
"start": 365,
"end": 370
},
{
"type": "Token[]",
"field": "arguments",
"text": "*",
"start": 371,
"end": 372,
"items": [
{
"type": "Token::Wildcard",
"text": "*",
"start": 371,
"end": 372
}
]
}
]
},
{
"type": "ComparisonOperator::GreaterThan",
"field": "operator",
"text": ">",
"start": 374,
"end": 375
},
{
"type": "Token::NumberLiteral",
"field": "right",
"text": "1",
"start": 376,
"end": 377
}
]
}
]
},
{
"type": "Clause::OrderBy",
"field": "orderBy",
"text": "order by age desc",
"start": 378,
"end": 395,
"fields": [
{
"type": "SortItem[]",
"field": "sortItems",
"text": "age desc",
"start": 387,
"end": 395,
"items": [
{
"type": "SortItem",
"text": "age desc",
"start": 387,
"end": 395,
"fields": [
{
"type": "Token::Identifier",
"field": "expression",
"text": "age",
"start": 387,
"end": 390
},
{
"type": "Keyword::SortDirection::Descending",
"field": "direction",
"text": "desc",
"start": 391,
"end": 395
}
]
}
]
}
]
},
{
"type": "Clause::Limit",
"field": "limit",
"text": "limit 10",
"start": 396,
"end": 404,
"fields": [
{
"type": "Token::NumberLiteral",
"field": "count",
"text": "10",
"start": 402,
"end": 404
}
]
}
]
},
{
"type": "Query",
"text": "Select p.product_name, c.category_name, p.price\nFrom products p\n Join categories c On p.category_id = c.id\nWhere p.price > (Select avg(price) From products Where category_id = p.category_id)\n And c.category_name In ('Books', 'Games')\nOrder By p.price Desc\nLimit 15",
"start": 407,
"end": 673,
"fields": [
{
"type": "Clause::Select",
"field": "select",
"text": "Select p.product_name, c.category_name, p.price",
"start": 407,
"end": 454,
"fields": [
{
"type": "Token[]",
"field": "items",
"text": "p.product_name, c.category_name, p.price",
"start": 414,
"end": 454,
"items": [
{
"type": "Token::ColumnReference",
"text": "p.product_name",
"start": 414,
"end": 428,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "p",
"start": 414,
"end": 415
},
{
"type": "Token::Identifier",
"field": "column",
"text": "product_name",
"start": 416,
"end": 428
}
]
},
{
"type": "Token::ColumnReference",
"text": "c.category_name",
"start": 430,
"end": 445,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "c",
"start": 430,
"end": 431
},
{
"type": "Token::Identifier",
"field": "column",
"text": "category_name",
"start": 432,
"end": 445
}
]
},
{
"type": "Token::ColumnReference",
"text": "p.price",
"start": 447,
"end": 454,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "p",
"start": 447,
"end": 448
},
{
"type": "Token::Identifier",
"field": "column",
"text": "price",
"start": 449,
"end": 454
}
]
}
]
}
]
},
{
"type": "Clause::From",
"field": "from",
"text": "From products p",
"start": 455,
"end": 470,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "products",
"start": 460,
"end": 468
},
{
"type": "Token::Identifier",
"field": "alias",
"text": "p",
"start": 469,
"end": 470
}
]
},
{
"type": "Clause::Join",
"field": "join",
"text": "Join categories c On p.category_id = c.id",
"start": 473,
"end": 514,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "categories",
"start": 478,
"end": 488
},
{
"type": "Token::Identifier",
"field": "alias",
"text": "c",
"start": 489,
"end": 490
},
{
"type": "Condition::Comparison",
"field": "condition",
"text": "p.category_id = c.id",
"start": 494,
"end": 514,
"fields": [
{
"type": "Token::ColumnReference",
"field": "left",
"text": "p.category_id",
"start": 494,
"end": 507,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "p",
"start": 494,
"end": 495
},
{
"type": "Token::Identifier",
"field": "column",
"text": "category_id",
"start": 496,
"end": 507
}
]
},
{
"type": "ComparisonOperator::Equal",
"field": "operator",
"text": "=",
"start": 508,
"end": 509
},
{
"type": "Token::ColumnReference",
"field": "right",
"text": "c.id",
"start": 510,
"end": 514,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "c",
"start": 510,
"end": 511
},
{
"type": "Token::Identifier",
"field": "column",
"text": "id",
"start": 512,
"end": 514
}
]
}
]
}
]
},
{
"type": "Clause::Where",
"field": "where",
"text": "Where p.price > (Select avg(price) From products Where category_id = p.category_id)\n And c.category_name In ('Books', 'Games')",
"start": 515,
"end": 642,
"fields": [
{
"type": "Condition::And",
"field": "condition",
"text": "p.price > (Select avg(price) From products Where category_id = p.category_id)\n And c.category_name In ('Books', 'Games')",
"start": 521,
"end": 642,
"fields": [
{
"type": "Condition[]",
"field": "conditions",
"text": "p.price > (Select avg(price) From products Where category_id = p.category_id)\n And c.category_name In ('Books', 'Games')",
"start": 521,
"end": 642,
"items": [
{
"type": "Condition::Comparison",
"text": "p.price > (Select avg(price) From products Where category_id = p.category_id)",
"start": 521,
"end": 598,
"fields": [
{
"type": "Token::ColumnReference",
"field": "left",
"text": "p.price",
"start": 521,
"end": 528,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "p",
"start": 521,
"end": 522
},
{
"type": "Token::Identifier",
"field": "column",
"text": "price",
"start": 523,
"end": 528
}
]
},
{
"type": "ComparisonOperator::GreaterThan",
"field": "operator",
"text": ">",
"start": 529,
"end": 530
},
{
"type": "Token::Subquery",
"field": "right",
"text": "(Select avg(price) From products Where category_id = p.category_id)",
"start": 531,
"end": 598,
"fields": [
{
"type": "Query",
"field": "query",
"text": "Select avg(price) From products Where category_id = p.category_id",
"start": 532,
"end": 597,
"fields": [
{
"type": "Clause::Select",
"field": "select",
"text": "Select avg(price)",
"start": 532,
"end": 549,
"fields": [
{
"type": "Token[]",
"field": "items",
"text": "avg(price)",
"start": 539,
"end": 549,
"items": [
{
"type": "Token::FunctionCall",
"text": "avg(price)",
"start": 539,
"end": 549,
"fields": [
{
"type": "Token::Identifier",
"field": "name",
"text": "avg",
"start": 539,
"end": 542
},
{
"type": "Token[]",
"field": "arguments",
"text": "price",
"start": 543,
"end": 548,
"items": [
{
"type": "Token::Identifier",
"text": "price",
"start": 543,
"end": 548
}
]
}
]
}
]
}
]
},
{
"type": "Clause::From",
"field": "from",
"text": "From products",
"start": 550,
"end": 563,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "products",
"start": 555,
"end": 563
}
]
},
{
"type": "Clause::Where",
"field": "where",
"text": "Where category_id = p.category_id",
"start": 564,
"end": 597,
"fields": [
{
"type": "Condition::Comparison",
"field": "condition",
"text": "category_id = p.category_id",
"start": 570,
"end": 597,
"fields": [
{
"type": "Token::Identifier",
"field": "left",
"text": "category_id",
"start": 570,
"end": 581
},
{
"type": "ComparisonOperator::Equal",
"field": "operator",
"text": "=",
"start": 582,
"end": 583
},
{
"type": "Token::ColumnReference",
"field": "right",
"text": "p.category_id",
"start": 584,
"end": 597,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "p",
"start": 584,
"end": 585
},
{
"type": "Token::Identifier",
"field": "column",
"text": "category_id",
"start": 586,
"end": 597
}
]
}
]
}
]
}
]
}
]
}
]
},
{
"type": "Condition::InPredicate",
"text": "c.category_name In ('Books', 'Games')",
"start": 605,
"end": 642,
"fields": [
{
"type": "Token::ColumnReference",
"field": "expression",
"text": "c.category_name",
"start": 605,
"end": 620,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "c",
"start": 605,
"end": 606
},
{
"type": "Token::Identifier",
"field": "column",
"text": "category_name",
"start": 607,
"end": 620
}
]
},
{
"type": "Token[]",
"field": "values",
"text": "'Books', 'Games'",
"start": 625,
"end": 641,
"items": [
{
"type": "Token::StringLiteral",
"text": "'Books'",
"start": 625,
"end": 632
},
{
"type": "Token::StringLiteral",
"text": "'Games'",
"start": 634,
"end": 641
}
]
}
]
}
]
}
]
}
]
},
{
"type": "Clause::OrderBy",
"field": "orderBy",
"text": "Order By p.price Desc",
"start": 643,
"end": 664,
"fields": [
{
"type": "SortItem[]",
"field": "sortItems",
"text": "p.price Desc",
"start": 652,
"end": 664,
"items": [
{
"type": "SortItem",
"text": "p.price Desc",
"start": 652,
"end": 664,
"fields": [
{
"type": "Token::ColumnReference",
"field": "expression",
"text": "p.price",
"start": 652,
"end": 659,
"fields": [
{
"type": "Token::Identifier",
"field": "table",
"text": "p",
"start": 652,
"end": 653
},
{
"type": "Token::Identifier",
"field": "column",
"text": "price",
"start": 654,
"end": 659
}
]
},
{
"type": "Keyword::SortDirection::Descending",
"field": "direction",
"text": "Desc",
"start": 660,
"end": 664
}
]
}
]
}
]
},
{
"type": "Clause::Limit",
"field": "limit",
"text": "Limit 15",
"start": 665,
"end": 673,
"fields": [
{
"type": "Token::NumberLiteral",
"field": "count",
"text": "15",
"start": 671,
"end": 673
}
]
}
]
}
]