Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if then query

Posted on 2011-09-06
5
Medium Priority
?
356 Views
Last Modified: 2012-05-12
Hi, I have a problem with an IF - THEN query:
I have attached the sql commands and the tables and what is my problem.
Sorry that i don't even try articulate the problem in text.



 SQL.doc
0
Comment
Question by:arielbf
  • 4
5 Comments
 
LVL 4

Expert Comment

by:Ara-
ID: 36488351
approved
Approved

Capital A in column name, but no in query?
0
 

Author Comment

by:arielbf
ID: 36488367
should be approved and not Approved
but this is not the real problem
it is not working anyway
0
 
LVL 4

Expert Comment

by:Ara-
ID: 36488388
Sorry, my bad. I can see now that it isn't the problem..
0
 
LVL 4

Expert Comment

by:Ara-
ID: 36488407
If you put a sum() around each of the if-entries like this:
sum(if(gp=2,approved,0)) AS aprtra

it should work.
0
 
LVL 4

Accepted Solution

by:
Ara- earned 2000 total points
ID: 36488420
SELECT sid,  sum(if(gp=1,approved,0)) AS aprstu, sum(if(gp=1,payed,0)) AS paystu, sum(if(gp=2,approved,0)) AS aprtra,sum(if(gp=2,payed,0)) AS paytra, sum(if(gp=3,approved,0)) AS aprenr,sum(if(gp=3,payed,0)) AS payenr, sum(if(gp=4,approved,0)) AS aprdor,sum(if(gp=4,payed,0)) AS paydor FROM grants WHERE sid=1 GROUP BY sid;
+------+--------+--------+--------+--------+--------+--------+--------+--------+
| sid  | aprstu | paystu | aprtra | paytra | aprenr | payenr | aprdor | paydor |
+------+--------+--------+--------+--------+--------+--------+--------+--------+
|    1 |  10000 |   3750 |   5100 |   3000 |   1000 |      0 |      0 |      0 |
+------+--------+--------+--------+--------+--------+--------+--------+--------+
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question