# Problem with query RollUp

Hi there, I need your appreciated help.

My incorrect output:

``````DRT	P > 16.5 	P <= 16.5 	tot ve	tot an	tot pi	tot	% pi	% tr
I	115		91		206	99	25	124	20	60
M	212		782		994	632	150	782	19	79
O	301		891		1192	544	345	889	39	75
S	74		101		175	87	34	121	28	69
S	702		1865		2567	1362	554	1916	29	75
``````

I need this output:

``````DRT	P > 16.5 	P <= 16.5 	tot ve	tot an	tot pi	tot	% pi	% tr
I	115		91		206	99	25	124	20	60
M	212		782		994	632	150	782	19	79
O	301		891		1192	544	345	889	39	75
S	74		101		175	87	34	121	28	69
Tot	702		1865		2567	1362	554	1916	29	75
``````

In the last row don’t have the field name `Tot` but `S` (last DRT) why?
Can you help me?

My query:

``````SELECT
COALESCE(Left(Zn,2),'Tot') DRT
, `P > 16.5`
, `P <= 16.5`
, `tot ve`
, `tot an`
, `tot pi`
, (`tot an`+`tot pi`) `tot`
, FORMAT((`tot pi`/(`tot an`+`tot pi`))*100,0) `% pi`
, FORMAT(((`tot an` + `tot pi`)/`tot ve`)*100,0) `% tr`

FROM (SELECT
Zn
, COUNT(*) 'tot ve'
, SUM(IF(p &gt; 16.5, 1, 0)) 'P &gt; 16.5'
, SUM(IF(p &lt;= 16.5, 1, 0)) 'P &lt;= 16.5'
, SUM(IF(AN='S', 1, 0)) 'tot an'
, SUM(IF(PI='S', 1, 0)) 'tot pi'
, '% pi'
, '% tr'

FROM tbl_q
WHERE 1
GROUP BY Left(Zn,2) WITH ROLLUP) x;

Time: 0.016ms
``````

I need relax…

``````
SELECT
COALESCE(DRT,'Tot') `DRT`
........

FROM (SELECT
LEFT(Zn,2) 'DRT'
........

``````