[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Include Count in Calculations

Posted on 2012-08-23
4
Medium Priority
?
379 Views
Last Modified: 2012-08-28
Hi Experts,

I'm not sure what the syntax is but I want to include a result from a count into another select statement so that I can do it all in one go?

I'm using Netezza with Aginity client.

SELECT (0.25+0.0006507)/(0.0006507+(0.25/SELECT COUNT(*)
FROM TABLE A))

Open in new window


Thanks,

OS
0
Comment
Question by:onesegun
4 Comments
 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 80 total points
ID: 38324278
SELECT (0.25+0.0006507)/(0.0006507+(0.25/(SELECT COUNT(*)
FROM TABLE A)))

You have to enclose the subquery in ()
0
 
LVL 25

Accepted Solution

by:
lwadwell earned 120 total points
ID: 38324343
or another way is

SELECT (0.25+0.0006507)/(0.0006507+(0.25/cnt))
FROM (SELECT COUNT(*) as cnt FROM TABLE A) v
0
 
LVL 7

Expert Comment

by:aplusexpert
ID: 38324352
Yes up to 32 level you can write in one select statement but in brackets

eg. SELECT (0.25+0.0006507)/(0.0006507+(0.25/(SELECT COUNT(*)
FROM TABLE A)))

Thanks...
0
 

Author Closing Comment

by:onesegun
ID: 38340298
Thanks chaps!<br /><br />-ps this point system is really annoying I wanted to award points to (Cluskitt - 15), (lwadwell - 20),  (aplusexpert - 15) as I thought everyone made a valid contribution but I am only allowed to award a minimum of 20 points per user??????
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 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