select left(trans_date,7) as [month], country, count([state]) as trans_count, count(case [state] when 'approved' then 1 else null) as approved_count, sum(amount) as trans_total_amount, sum(case [state] when 'approved' then amount else 0) as approved_total_amount from Transactions group by country,[month] 报[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near ')'. (102) (SQLExecDirectW) 请修正
时间: 2024-04-16 11:26:33 浏览: 191
请将查询语句中的方括号([])替换为双引号(""),并在group by子句中使用别名替代列名。修正后的查询语句如下:
```sql
SELECT LEFT(trans_date, 7) AS "month",
country,
COUNT([state]) AS trans_count,
COUNT(CASE [state] WHEN 'approved' THEN 1 ELSE NULL END) AS approved_count,
SUM(amount) AS trans_total_amount,
SUM(CASE [state] WHEN 'approved' THEN amount ELSE 0 END) AS approved_total_amount
FROM Transactions
GROUP BY country, "month";
```
阅读全文