我有一个生成许多 SQL 语句的应用程序,其选择字段都包含AS
子句,如下所示:
SELECT TOP 200 [customer_name] AS [Customer Name], [customer_age] AS [Customer Age], AVG([customer_age]) AS 'Average Customer Age' FROM [tb_customers] GROUP BY [customer_age]
我的陈述将始终采用这种格式。我的任务是解析它们,以便删除“TOP 200”以及除聚合之外的AS
所有子句。换句话说,我想解析语句,在这种情况下,它会像这样结束:
SELECT [customer_name], [customer_age], AVG([customer_age]) AS 'Average Customer Age' FROM [tb_customers] GROUP BY [customer_age]
我该怎么做呢?是否有可能,因为这似乎是一项非常复杂的解析任务,因为字段的数量永远不会相同。如果有帮助,我有一个变量来存储其中的字段数量(不包括聚合)。