Solved

SQL Syntax

Posted on 2014-01-23
5
258 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
  • 3
  • 2
5 Comments
 
LVL 142

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 142

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 142

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now