我在页面上正确显示数据时遇到了困难。我正在运行一个帐单报告查询,该报告搜索所有未结帐单,我想将它们显示在一个页面上,未结余额按余额的年龄显示。因此,如果客户 ABC 在过去一年中有 10 张发票,其中一些有未结余额,我想在 0-30 / 30-60 / 60-90 / 和 90+ 天的列中显示这些余额。这是我所拥有的...
$sql17 = "SELECT $mysql_billing.primary_key, $mysql_billing.a_name, $mysql_billing.invoicedate, $mysql_billing.finaltotal, $mysql_billing_dates.paidtotal,
($mysql_billing.finaltotal - $mysql_billing_dates.paidtotal) AS total
FROM
(SELECT $mysql_billing.primary_key, $mysql_billing.a_name, $mysql_billing.login_username, $mysql_billing.invoicedate,
SUM($mysql_billing.custotal) AS finaltotal
FROM $mysql_billing where $today >= invoicedate AND $start_search_prev180_date <= invoicedate AND custotal != payments GROUP BY login_username) $mysql_billing
LEFT JOIN
(SELECT $mysql_billing_dates.id, $mysql_billing_dates.username,
SUM($mysql_billing_dates.amount) AS paidtotal
FROM $mysql_billing_dates where complete != 'yes' GROUP BY username) $mysql_billing_dates
ON ($mysql_billing.login_username = $mysql_billing_dates.username)
GROUP BY a_name ORDER BY a_name ASC";
这似乎打印出结果,但是如何根据超过 1 个日期变量将结果放入不同的列中?我必须做 4 个单独的查询吗?