Sql 内部联接-字段的计数和和

Sql 内部联接-字段的计数和和,sql,Sql,我有两个表editors和title\u editors,我正试图运行一个内部联接查询,以显示所有编辑器以及它们编辑的图书数量。我并没有得到期望的结果,而是得到了所有编辑过的书籍的总和。如何列出所有编辑的姓名以及他们编辑的图书数量,并安排报告,以便首先列出编辑最多图书的编辑 质疑 表模式 create table editors (editor_id char(11) not null, editor_lname varchar(40) not null, editor_fname

我有两个表
editors
title\u editors
,我正试图运行一个内部联接查询,以显示所有编辑器以及它们编辑的图书数量。我并没有得到期望的结果,而是得到了所有编辑过的书籍的总和。如何列出所有编辑的姓名以及他们编辑的图书数量,并安排报告,以便首先列出编辑最多图书的编辑

质疑

表模式

create table editors    (editor_id char(11) not null,   editor_lname varchar(40) not null,  editor_fname varchar(20) not null,  editor_positon varchar(12) null,    phone char(12) null,    address varchar(40) null,   city varchar(20) null,  state char(2) null, zip char(5) null,   ed_boss char(11) null );
create table title_editors  (editor_id char(11) not null,   title_id char(6) not null,  editor_order tinyint null);

除了关于CONCAT的评论外,您还缺少GROUP BY,以及ORDER BY末尾的DESC,以便按照您想要的方式对其进行排序

SELECT
  CONCAT(e.editor_fname,' ',e.editor_lname),
  SUM(te.editor_order)
FROM
  editors e
INNER JOIN
  title_editors te
  ON te.editor_id = e.editor_id
GROUP BY
  e.editor_fname,
  e.editor_lname
ORDER BY
  SUM(te.editor_order) DESC;

除了关于CONCAT的评论外,您还缺少您的GROUP BY,以及订单末尾的DESC BY,以便按照您想要的方式对其进行排序

SELECT
  CONCAT(e.editor_fname,' ',e.editor_lname),
  SUM(te.editor_order)
FROM
  editors e
INNER JOIN
  title_editors te
  ON te.editor_id = e.editor_id
GROUP BY
  e.editor_fname,
  e.editor_lname
ORDER BY
  SUM(te.editor_order) DESC;

除了关于CONCAT的评论外,您还缺少您的GROUP BY,以及订单末尾的DESC BY,以便按照您想要的方式对其进行排序

SELECT
  CONCAT(e.editor_fname,' ',e.editor_lname),
  SUM(te.editor_order)
FROM
  editors e
INNER JOIN
  title_editors te
  ON te.editor_id = e.editor_id
GROUP BY
  e.editor_fname,
  e.editor_lname
ORDER BY
  SUM(te.editor_order) DESC;

除了关于CONCAT的评论外,您还缺少您的GROUP BY,以及订单末尾的DESC BY,以便按照您想要的方式对其进行排序

SELECT
  CONCAT(e.editor_fname,' ',e.editor_lname),
  SUM(te.editor_order)
FROM
  editors e
INNER JOIN
  title_editors te
  ON te.editor_id = e.editor_id
GROUP BY
  e.editor_fname,
  e.editor_lname
ORDER BY
  SUM(te.editor_order) DESC;

把你的结果分组

SELECT (CONCAT(e.editor_fname,' ',e.editor_lname)) as Editor_Name
  , SUM(te.editor_order) as Books_Edited 
FROM editors e
INNER JOIN title_editors te 
  ON te.editor_id = e.editor_id 
GROUP BY e.editor_fname,e.editor_lname
ORDER BY Books_Edited;

把你的结果分组

SELECT (CONCAT(e.editor_fname,' ',e.editor_lname)) as Editor_Name
  , SUM(te.editor_order) as Books_Edited 
FROM editors e
INNER JOIN title_editors te 
  ON te.editor_id = e.editor_id 
GROUP BY e.editor_fname,e.editor_lname
ORDER BY Books_Edited;

把你的结果分组

SELECT (CONCAT(e.editor_fname,' ',e.editor_lname)) as Editor_Name
  , SUM(te.editor_order) as Books_Edited 
FROM editors e
INNER JOIN title_editors te 
  ON te.editor_id = e.editor_id 
GROUP BY e.editor_fname,e.editor_lname
ORDER BY Books_Edited;

把你的结果分组

SELECT (CONCAT(e.editor_fname,' ',e.editor_lname)) as Editor_Name
  , SUM(te.editor_order) as Books_Edited 
FROM editors e
INNER JOIN title_editors te 
  ON te.editor_id = e.editor_id 
GROUP BY e.editor_fname,e.editor_lname
ORDER BY Books_Edited;

在SQLFIDLE示例中,您使用MySQL进行了设置,但使用了
|
操作符进行连接。MySQL通常不支持这种连接,相反,连接是像CONCAT(例如first_name,,,e.last_name)那样进行的。您实际使用的是Oracle还是其他数据库?@MichaelBerkowski,它的sql。抱歉,它不允许我执行oracle。架构不是oracle数据类型。不过,将GROUP BY添加到查询中应该会修复SUM()。@Shawn,很抱歉刚刚意识到这一点。在您的SQLFIDLE示例中,您使用MySQL设置了GROUP BY,但正在使用
|
操作符进行连接。MySQL通常不支持这种连接,相反,连接是像CONCAT(例如first_name,,,e.last_name)那样进行的。您实际使用的是Oracle还是其他数据库?@MichaelBerkowski,它的sql。抱歉,它不允许我执行oracle。架构不是oracle数据类型。不过,将GROUP BY添加到查询中应该会修复SUM()。@Shawn,很抱歉刚刚意识到这一点。在您的SQLFIDLE示例中,您使用MySQL设置了GROUP BY,但正在使用
|
操作符进行连接。MySQL通常不支持这种连接,相反,连接是像CONCAT(例如first_name,,,e.last_name)那样进行的。您实际使用的是Oracle还是其他数据库?@MichaelBerkowski,它的sql。抱歉,它不允许我执行oracle。架构不是oracle数据类型。不过,将GROUP BY添加到查询中应该会修复SUM()。@Shawn,很抱歉刚刚意识到这一点。在您的SQLFIDLE示例中,您使用MySQL设置了GROUP BY,但正在使用
|
操作符进行连接。MySQL通常不支持这种连接,相反,连接是像CONCAT(例如first_name,,,e.last_name)那样进行的。您实际使用的是Oracle还是其他数据库?@MichaelBerkowski,它的sql。抱歉,它不允许我执行oracle。架构不是oracle数据类型。不过,将GROUP BY添加到查询中应该可以修复SUM()。@Shawn,很抱歉刚刚意识到这一点