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

x
?
Solved

SQL Syntax

Posted on 2014-01-23
5
Medium Priority
?
268 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
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

671 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