gpt4 book ai didi

mysql - Mysql命令不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:30 25 4
gpt4 key购买 nike

我有两个名为用户和提交的表。我想自然地加入他们。然后将它们按列分组。然后选择两列。给他们起别名。然后按给定的别名对它们进行排序。

我的代码已在下面给出。

select name, count(result) as name, tried from user
natural join submission group by name sort by tried;

但是,这是行不通的。我得到一个错误:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sort by count(result) LIMIT 0, 30' at line 2

最佳答案

您有两个同名的结果:

select name, <-- 1st "anme"
count(result) as name, <-- 2nd name
tried from user natural join submission group by name order by tried;

修复很简单,因为您需要做的就是更改 COUNT 结果的别名

select name, 
count(result) as result_count,
tried from user natural join submission group by name order by tried;

关于mysql - Mysql命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13437017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com