php – 每月总计月份返回NULL,仅输出运行总计

前端之家收集整理的这篇文章主要介绍了php – 每月总计月份返回NULL,仅输出运行总计前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我使用以下内容尝试以如下格式输出我的月度总计:

 January
 Quoted Total : £678
 Parts Total : £432
 Profit Total : £244

 February
 Quoted Total : £650
 Parts Total : £345
 Profit Total : £123

等等……….

    // Work Complete Totals
    $query = $db->query("SELECT SUM(pricequoted) AS pricequotedtotal,SUM(partprice) AS partpricetotal,SUM(profit) profittotal,DATE_FORMAT('%Y-%m',completeddate) AS month 
                         FROM `jobdetails` 
                         WHERE jobstatus='complete'
                         GROUP BY DATE_FORMAT('%Y-%m',completeddate)");


    echo '

我得到的问题是它只输出运行总计,所以我在页面底部的ONCE得到以下内容,但仅此而已:

Work Complete Totals
Quoted Total : £1460.00

Parts Total : £541.43

Profit Total : £918.57

如果我在PHPmyadmin中运行上面的查询,我得到结果:

pricequotedtotal    partpricetotal  profittotal        month
      1460              541.43      918.5699999999998   NULL

我的表格布局如下:

id  customerID  name    facebookuserurl tel email   address itemforrepair   repairdetails   otherdetails    pricequoted partprice   profit  datepartordered jobstatus   dateofcompletion    datecreated itemnumber

以下是一个示例行:

49  37ac4   Ellen Frost https://www.facebook.com/ellen.mccormick.18             Galaxy S3 (Fullsize) Blue   Broken front glass and also digitiser not working.  Quoted customer on whole lcd,digitiser assembly r...   140 114.98  25.02   2013-05-02  complete    2013-05-08  2013-05-01  251258104217

编辑>>
下面是表格中几行的屏幕截图.

编辑>>

这是我的表结构:

最佳答案
你需要改变它

DATE_FORMAT('%Y-%m',completeddate)

DATE_FORMAT(completeddate,'%Y-%m')

这就是你在月份列中得到NULL的原因,因此只有一行.

manual entry.

原文链接:https://www.f2er.com/mysql/434285.html

猜你在找的MySQL相关文章