我正在尝试构建(无论如何在我看来)应该是一个简单的 SQL 查询,以了解每个财政年度为客户开具的发票。输出可能如下所示:
{clientName (Client A)} - {2010/2011 Value} - {2011/2012 Value} - {2012/2013 Value}
我能够实现的是如下所示的输出:
{clientName (Client A)} - {2010/2011 Value}
{clientName (Client A)} - {2011/2012 Value}
{clientName (Client A)} - {2012/2013 Value}
{clientName (Client B)} - {2010/2011 Value}
等等……</p>
现在,我知道这是不正确的,但我正在使用的查询如下所示:
$query = "SELECT i.invoiceValue, fy.year, c.clientName, c.clientID FROM cms_invoices i
LEFT JOIN cms_financialYear fy ON fy.yearID = i.yearID
LEFT JOIN cms_projects p ON p.projectID = i.projectID
LEFT JOIN cms_clients c ON c.clientID = p.clientID
ORDER BY fy.year, c.clientName";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo $row['year'] . " - ";
echo $row['clientName'] . " - $";
echo number_format($row[invoiceValue], 2, '.', ',') . "";
echo "<br>";
如果我能对此有所指导,我将不胜感激。我已经尝试了几个小时,但很遗憾,没有运气。
谢谢,@rrfive