SELECT a.invoice_id,
invoice_no,
a.cs_no,
identity,
name,
model,
body_color,
lot_no,
key_no,
serial_no,
location,
buyoff_date,
received_date,
tagged_date,
invoice_date,
a.pullout_date,
vin_no,
engine_no,
order_no,
b.approve,
COUNT(a.cs_no) AS buyoff_count,
SUM(CASE WHEN received_date IS NULL THEN 0 ELSE 1 END) AS received_count,
SUM(CASE WHEN tagged_date IS NULL THEN 0 ELSE 1 END) AS tagged_count,
SUM(CASE WHEN invoice_date IS NULL THEN 0 ELSE 1 END) AS invoice_count,
SUM(CASE WHEN a.pullout_date IS NULL THEN 0 ELSE 1 END) AS pullout_count
FROM buy_off a
LEFT JOIN pull_out b
ON a.invoice_id = b.invoice_id
AND a.cs_no = b.cs_no
WHERE tagged_date IS NOT NULL
AND invoice_date IS NULL
GROUP BY identity, tagged_date, invoice_id WITH ROLLUP
我上面的代码输出如下:
invoice_id identity tagged_date
1 a 2/5/2015
total = 1
2 a 2/6/2015
3 a 2/6/2015
total = 2
4 b 2/5/2015
total = 1
5 b 2/6/2015
total = 1
grand total = 5
但这就是我想要的:
invoice_id identity tagged_date
1 a 2/5/2015
2 a 2/6/2015
3 a 2/6/2015
total = 3
4 b 2/5/2015
5 b 2/6/2015
total = 2
grand total = 5
你们可以请帮助实现上述输出.....在此先感谢:d