【问题标题】:SQL request 3 linked tablesSQL请求3个链接表
【发布时间】:2017-08-27 22:41:14
【问题描述】:

我有 3 张桌子:

我想要这个结果:

我尝试使用 order by,但它不起作用, 有人有想法

【问题讨论】:

标签: mysql sql database request linked-tables


【解决方案1】:

您可以使用GROUP BY 进行INNER JOIN,例如:

SELECT s.number AS supplier, c.category AS category, s.date as `date`, COUNT(r.*)
AS total
FROM supplier s JOIN register r ON s.id = r.supplier_id
JOIN category c ON c.id = r.category_id
GROUP BY s.number, c.category, s.date;

【讨论】:

    【解决方案2】:

    假设链接服务器名称为 [LinkedSample\Tables] 然后就可以使用下面的代码了:

    SELECT s.number AS supplier, c.category AS category, s.date as `date`, COUNT(r.*) AS total
    FROM  [LinkedSample\Tables].supplier s 
    JOIN [LinkedSample\Tables].register r ON s.id = r.supplier_id 
    JOIN [LinkedSample\Tables].category c ON c.id = r.category_id
    GROUP BY s.number, c.category, s.date;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 2013-10-16
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      相关资源
      最近更新 更多