select action,count(*) num from user_log group by action desc这个语法在mysql8.0.33中使用为什么报错 java.sq.SQLSyrtaxErrorException: You have an error in your SQL syntax; check the manual thta corresponds your MySQL server version for the right syntax to use near 'desc' at line 1
时间: 2023-07-03 12:25:27 浏览: 99
在 MySQL 中,关键字 `DESC` 用于指定降序排序,如果将其作为列名或别名使用,会导致语法错误。
在你的语句中,`DESC` 是作为 `GROUP BY` 的排序方式使用的,而不是 `ORDER BY` 的排序方式。因此,如果你想要按 `action` 列降序排序,应该将 `DESC` 放在 `ORDER BY` 子句中,而不是 `GROUP BY` 子句中,如下所示:
```
SELECT action, COUNT(*) AS num
FROM user_log
GROUP BY action
ORDER BY action DESC;
```
这样就可以按 `action` 列降序排序了。
相关问题
select action,count(*) as num from user_log group by action desc这个语句在mysql8.0.33这使用为什么desc会报错
在 MySQL 中,关键字 `DESC` 用于指定降序排序,如果将其作为列名或别名使用,会导致语法错误。
在你的语句中,`DESC` 用于指定 `GROUP BY` 的降序排序,因此导致了语法错误。如果你想要按 `action` 列倒序排序,应该将 `DESC` 放在 `ORDER BY` 子句中,如下所示:
```
SELECT action, COUNT(*) AS num
FROM user_log
GROUP BY action
ORDER BY action DESC;
```
这样就可以按 `action` 列倒序排序了。
oracle中这个语法错在哪了select * from Mynumbers group by num having count(num) < 2 order by num desc limit 1;
这个语法在 Oracle 中是不合法的,因为在 SELECT 语句中使用了 LIMIT 子句,而 LIMIT 子句是 MySQL 特有的,Oracle 中没有这个语法。如果想要在 Oracle 中实现相同的功能,可以使用 ROWNUM 来限制查询结果的数量,例如:
SELECT *
FROM (
SELECT *
FROM Mynumbers
GROUP BY num
HAVING COUNT(num) < 2
ORDER BY num DESC
)
WHERE ROWNUM = 1;
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)