【发布时间】:2015-07-07 15:24:00
【问题描述】:
我需要在表中查询一些已开票、已收、已调整的金额,但还需要加入表中的服务样本计数
我可以单独请求,但我希望将结果很好地放在一个数组中
这是我认为可行的查询
SELECT ROUND(SUM(`amount_billed`/1000),2) AS `billed`,
ROUND(SUM(`amount_received`/1000),2) AS `received`,
ROUND(SUM(`amount_adjusted`/1000),2) AS `adjustment` FROM `acs`.`billing` AS **`amount`**
INNER JOIN (SELECT COUNT(`accession_id`) AS `samples` FROM `acs`.`billing` AS **`count`**
WHERE year(`count`.`date_billed`) = 2012 AND year(`count`.`date_paid`) = 2012
HAVING COUNT(`accession_id`) > 1) WHERE year(`amount`.`date_billed`) = 2012 AND year(`amount`.`date_paid`) = 2012;
但是 MySQL 返回错误:
错误代码:1248。每个派生表都必须有自己的别名
我为选择查询amount 和连接count 为所有表指定了一个别名。
【问题讨论】:
-
INNER JOIN中SELECT count('accession_id').... >1)的派生表没有别名。 -
哦,是的,现在我看到了 :) 谢谢
标签: mysql join left-join inner-join mysql-error-1248