Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

if then query

Posted on 2011-09-06
5
Medium Priority
?
355 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 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
What we learned in Webroot's webinar on multi-vector protection.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
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…

661 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