Solved

SQL Syntax

Posted on 2014-01-23
5
267 Views
Last Modified: 2014-01-23
What I really want is where c.POPU is MAX

SELECT
     s.SCTYPE,
     ROUND(SUM(c.POPU / c.POUEST) * c.POEST / SUM(c.POPU), 4) 'UNIT COST'
     FROM ccode c
     INNER JOIN job j ON c.JOB_ID = j.JOB_ID
     INNER JOIN sccode s ON s.SCCODE_ID = c.SCCODE_ID
     INNER JOIN sctype t ON t.SCTYPE_ID = s.SCTYPE
WHERE j.JOB_ID = 7398
AND c.POPU > 1
GROUP BY t.SCTYPE;
0
Comment
Question by:hdcowboyaz
[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
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39804939
you could add a "simple" condition like this:
SELECT
     s.SCTYPE,
     ROUND(SUM(c.POPU / c.POUEST) * c.POEST / SUM(c.POPU), 4) 'UNIT COST'
     FROM ccode c
     INNER JOIN job j ON c.JOB_ID = j.JOB_ID
     INNER JOIN sccode s ON s.SCCODE_ID = c.SCCODE_ID
     INNER JOIN sctype t ON t.SCTYPE_ID = s.SCTYPE
WHERE j.JOB_ID = 7398
AND c.POPU > 1
and c.popu = ( select max ( x.popu ) from ccode x )
GROUP BY t.SCTYPE;  

Open in new window


this new subquery might need more, especially if you want this for the relevant job


SELECT
     s.SCTYPE,
     ROUND(SUM(c.POPU / c.POUEST) * c.POEST / SUM(c.POPU), 4) 'UNIT COST'
     FROM ccode c
     INNER JOIN job j ON c.JOB_ID = j.JOB_ID
     INNER JOIN sccode s ON s.SCCODE_ID = c.SCCODE_ID
     INNER JOIN sctype t ON t.SCTYPE_ID = s.SCTYPE
WHERE j.JOB_ID = 7398
AND c.POPU > 1
and c.popu = ( select max ( x.popu ) from ccode x where x.job_id = j.job_id )
GROUP BY t.SCTYPE;  

Open in new window


hope this helps
0
 

Author Comment

by:hdcowboyaz
ID: 39804997
Query : SELECT      s.SCTYPE,      ROUND(SUM(c.POPU / c.POUEST) * c.POEST / SUM(c.POPU), 4) 'UNIT COST'      FROM ccode c      INNER JOI...
Error Code : 1305
FUNCTION jds.max does not exist
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39805005
that error code is not really related to the code posted?
0
 

Author Comment

by:hdcowboyaz
ID: 39805019
Yes it is. Why does it make sense for me to post some other error?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39805031
I think I know the issue. MySQL doens't like spaces with function/brackets
SELECT
     s.SCTYPE,
     ROUND(SUM(c.POPU / c.POUEST) * c.POEST / SUM(c.POPU), 4) 'UNIT COST'
     FROM ccode c
     INNER JOIN job j ON c.JOB_ID = j.JOB_ID
     INNER JOIN sccode s ON s.SCCODE_ID = c.SCCODE_ID
     INNER JOIN sctype t ON t.SCTYPE_ID = s.SCTYPE
WHERE j.JOB_ID = 7398
AND c.POPU > 1
and c.popu = ( select max(x.popu) from ccode x where x.job_id = j.job_id )
GROUP BY t.SCTYPE;  

Open in new window

0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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