Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP Mysql案例的每日销售报告_Php_Mysql - Fatal编程技术网

使用PHP Mysql案例的每日销售报告

使用PHP Mysql案例的每日销售报告,php,mysql,Php,Mysql,我需要根据下面的查询得到每日销售报告 这是我的桌子结构 orderid resid payment_type ordertotalprice orderdate 1 10 cod 50 2016-06-14 2 10 cod 10 2016-06-14 3 10 creditcard 40

我需要根据下面的查询得到每日销售报告

这是我的桌子结构

orderid resid   payment_type    ordertotalprice orderdate
1       10      cod             50              2016-06-14 
2       10      cod             10              2016-06-14
3       10      creditcard      40              2016-06-14 
4       10      cod             30              2016-06-14
5       10      creditcard      20              2016-06-14 
6       10      cod             10              2016-06-14
7       10      creditcard      20              2016-06-14 
8       11      cod             10              2016-06-14
我需要下面的输出结果使用上表

resid total_orders_cnt total_sales total_orders_cash total_sales_cash   total_orders_cc total_sales_cc
10    7                180         4                 100                    3               80
11    1                10          1                 10                     0               0
我正在使用下面的查询,但它并没有得到我想要的确切结果

SELECT COUNT(orderid) AS total_orders_cnt, SUM(ordertotalprice) AS total_sales,
        SUM(CASE WHEN (payment_type= 'cod') THEN 1 ELSE 0 END) AS total_orders_cash,
        CASE WHEN (payment_type= 'cod') THEN SUM(ordertotalprice) ELSE 0 END AS total_sales_cash,
        SUM(CASE WHEN (payment_type = 'creditcard') THEN 1 ELSE 0 END) total_orders_cc,
        CASE WHEN (payment_type = 'creditcard') THEN SUM(ordertotalprice) ELSE 0 END AS total_sales_cc
FROM order WHERE resid='10' AND orderdate = '2016-06-14';
所以请任何人帮助我

提前感谢

请尝试以下方法:

选择COUNT(orderid)作为总订单数,
总和(ordertotalprice)作为总销售额,
金额(当付款类型为“cod”时,则为1,否则为0结束)作为总订单金额或现金金额,
总金额(付款类型为“cod”,然后订单总价结束时的情况)作为总销售额现金,
金额(当付款类型为“信用卡”时,则为1,否则为0结束)订单总数,
总额(当付款类型为“信用卡”,然后是ordertotalprice END时的情况)作为总销售额
从命
其中,剩余值='10'和订单日期='2016-06-14';

@mikejohnvino很高兴我能帮忙。如果此答案有助于您解决问题,请将此答案或任何其他答案标记为已接受。如果他们是问题解决者且您批准,请为每个问题标记一个答案。你们可以这样做,就像下面的Giorgos或其他人一样。你的问题,20岁,没有一个被接受。谢谢