sql in mysql to select data

The data is like in picture    but I want to make report like this How can I do it with sql state ment (mysql)

                         
                     pin        pfi           ppr
David            200       100         500

Robert           40             0         260

Jhon              270         180       30
viilage.JPG
teeraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bradleys40Commented:
select (usernamefield) as name. (fieldname for pin) as pin, (fieldname for pfi) as pfi, (fieldname for pppr) as ppr
from table name
group by (useranamefield)
0
Jinesh KamdarCommented:
I don't see relevance of the supplied data with the required output! Are you sure you have attached the right data-set ?
0
teeraAuthor Commented:
excuseme the picture is not corect the corec is
table.JPG
0
Jinesh KamdarCommented:
Try these.
SELECT membernameH,
       SUM(CASE WHEN htype = 'pin' THEN amount ELSE 0 END) AS pin,
       SUM(CASE WHEN htype = 'pfi' THEN amount ELSE 0 END) AS pfi,
       SUM(CASE WHEN htype = 'ppr' THEN amount ELSE 0 END) AS ppr
FROM table
GROUP BY membernameH;
 
OR
 
SELECT membernameH,
       SUM(IIF(htype = 'pin', amount, 0) AS pin,
       SUM(IIF(htype = 'pfi', amount, 0) AS pfi,
       SUM(IIF(htype = 'ppr', amount, 0) AS ppr
FROM table
GROUP BY membernameH;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.