【问题标题】:SQL, Count statementSQL,计数语句
【发布时间】:2021-08-10 22:58:02
【问题描述】:
select count(characterid) as num , schoolhouseid
from student natural join Character

几乎是 SQL 的初学者,试图找出 count 语句导致语法崩溃的原因。 它可以在没有 schoolhouseid 和 count 的情况下工作,但一起崩溃

【问题讨论】:

  • 您希望结果如何? Count(characterid) 将返回一个值,而 scoulhouseid 将为集合中的每一行返回一个值。也许您想按 schoulehouseid 分组?
  • 请提供样本数据、所需结果和适当的数据库标签。很遗憾你在不了解onusing 子句的情况下学习所谓的“自然连接”。

标签: sql select syntax count


【解决方案1】:

这取决于你想要的输出是什么,但看起来你正在尝试这样做:

select count(*) as num , schoolhouseid
from student
group by schoolhouseid

这会为您提供每个校舍中的行数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-22
    相关资源
    最近更新 更多