select Actor1CountryCode,COUNT(Actor1CountryCode as shu ,AVG(AvgTone) AS CO from (SELECT * from cvs where locate('covid', SOURCEURL) AND Actor2CountryCode="USA") as g WHERE SQLDATE>=20191201 and SQLDATE<=20200601 GROUP BY Actor1CountryCode ORDER BY CO;有错误,请修改
时间: 2024-01-25 21:03:27 浏览: 136
确实存在语法错误,正确的 SQL 语句如下:
```
SELECT Actor1CountryCode, COUNT(Actor1CountryCode) AS shu, AVG(AvgTone) AS CO
FROM (
SELECT * FROM cvs
WHERE LOCATE('covid', SOURCEURL) > 0 AND Actor2CountryCode = 'USA' AND SQLDATE BETWEEN 20191201 AND 20200601
) AS g
GROUP BY Actor1CountryCode
ORDER BY CO;
```
修改说明:
- `COUNT` 函数只需要包含需要计数的字段即可,不需要使用 `AS` 进行命名。
- `LOCATE` 函数的返回值为位置索引,需要判断是否大于 0。
- 字符串需要使用单引号进行包裹。
- 时间范围需要使用 `BETWEEN` 进行判断。
- `AVG` 函数需要放在外层的 `SELECT` 语句中进行计算。
- SQL 语句中的关键字需要大写。
阅读全文