[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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
0
teera
Asked:
teera
  • 2
1 Solution
 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now