SHORT REPORT table:
--------------
id t_deep t_tanning amount cashier
-----------------------------------------
1 deep pro tan 30 1
2 facial tanning 25 2
3 deep pro tan 30 1
4 deep tanning 25 1
report html result:
table id cashier(40%) owns(60%) total
1 12 18 30
2 10 15 25
3 12 18 30
4 10 15 25
期待结果:
table id cashier owns total
1 0 30 30
2 10 15 25
3 0 30 30
4 10 15 25
php计算拆分40%和60%:
$q = $db->query("SELECT cashier, SUM(r_amount) AS amount, SUM(r_amount*0.60) AS totalSixty, SUM(r_amount*0.40) AS totalFourty FROM report
LEFT JOIN cashier ON cashier.id_cashier = report.id_cashier
WHERE date='$today' GROUP BY id_cashier");
// query to search pro tan
$q1 = $db->query("SELECT cashier, SUM(r_amount) AS amount, SUM(r_amount*0.60) AS totalSixty, SUM(r_amount*0.40) AS totalFourty FROM report
LEFT JOIN cashier ON cashier.id_cashier = report.id_cashier
WHERE date='$today' AND t_tanning LIKE 'Pro Tan%' GROUP BY id_cashier");
$sixtyPercent = number_format($r['totalSixty'],2);
$fourtyPercent = number_format($r['totalFourty'],2);
答案 0 :(得分:1)
您可以执行SUM(IF(t_tanning = 'pro tan',amount*0.6, amount))
之类的条件求和来执行1次查询。