473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SELECT TOP 50 PERCENT for group?

Does anyone know how I would modify this query so that it will return the TOP 50% FAC_METRIC values for each PROJECT_NAME?

I have read a few posts about using a subquery as criteria for field FAC_METRIC?

But, I can't seem to make it work???? Thanks!

SELECT qryQuartileStep3a.PROJECT_NAME, qryQuartileStep3a.SYSTEM_FACILITY, qryQuartileStep3a.FAC_METRIC
FROM qryQuartileStep3a
ORDER BY qryQuartileStep3a.FAC_METRIC;
Mar 25 '08 #1
2 6275
Stewart Ross
2,545 Expert Mod 2GB
Hi. There is no direct way to return a percentage of rows in SQL. You may be confusing the SELECT TOP N predicate in SQL. TOP N just returns the specified number of rows (if they exist); it does not select the TOP N rows within a grouping, nor does it handle percentages.

To return a percentage of the rows you would need to know the count of the number of rows for each group within your query. You can do this as a separate Count query, but what you do after that could get quite complex in SQL. I can't think of a direct approach using subqueries which would help you either.

This is really a job for Excel... something I find myself saying fairly frequently now in response to posts of this nature. Databases are good at data handling and organisation, particularly in a multi-table multi-relation context, but they are not anywhere near as strong when it comes to flexible statistical analysis as Excel is. Export the data to Excel and let it do the statistical analysis. As an example of the difference, just try finding the median* value of a particular group in Access through application of SQL queries alone and you will see what I mean...

-Stewart

*median is the mid-point value in a set of ordered numeric data
Mar 25 '08 #2
Hi Stuart,

Thanks once again for the response. Like you suggest, I am currently dumping the data into excel to run the quartile calculation and then bringing the results back into the database, it works, but its a little clunky.

I have been working on trying to find a more "dynamic" solution for this quartile calculation. I have been able to build a series of six queries that will work for a single series, but it is terribly slow, and will not work with multiple data groups. There may be some hope as SQL 2005 apparently has some upgraded functions including Row_Number which could turn out promising, our upgrade is pending, so we'll have to see.

Anyway, I thought I would throw this out there to see if anyone had any tricks to share to get this done.

Thanks again.

Mike
Mar 26 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Nothing | last post by:
This is going to be a really stupid question, but I am having a problem with the percent format in a control on a form. My end goal is that I want the user to enter 17 and have the control...
2
by: mhodkin | last post by:
I created a query in which I have grouped data by City. I wish to calculate the percent of each value, e.g. City/(Total count of all Cities), in tbe next column of the query. I can't seem to...
4
by: Brad | last post by:
I need to select the Top 50 records from a table of over 10,000 records and all is working just fine, but I have a what if question. What if the 50th record's value matches the 51st record (and...
29
by: pb648174 | last post by:
I have the following basic statements being executed: Create a temp table, #TempPaging Insert Into #TempPaging (Col1, Col2) Select Col1, Col2 From SomeOtherTable Order By Col2, Col1 Select...
39
by: VidTheKid | last post by:
THE PROBLEM The % symbol is too vague when defining dimensions in CSS and HTML. It can relate to an inherited value, a measure of the containing element (which can differ between box models) or...
5
by: cecil | last post by:
Hi All, I have a report sectioned/grouped by year with number fields (i,e attendance). I would like to calculate percent difference of attendance for each year. Thanks in advance, Cecil
1
by: rehanmomin | last post by:
BACKGROUND I was trying the figure out a query for my sisters optometrist office. I have two tables, one that contains customers demographics and another table that contains patient's examination. ...
4
by: gagnonconsulting | last post by:
Hi, This is driving me crazy, but I am sure I am missing something simple. I have built an Access 2007 report that shows 2 rows of sales data from each of a bunch of store locations. My table has...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.