Solved

if then query

Posted on 2011-09-06
5
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

751 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