我需要在表格中查询一些已开票、已收到、已调整的金额,但还需要加入表格中的样本数量
我可以单独请求,但我希望将结果很好地放在一个数组中
这是我认为可行的查询
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
。