473,326 Members | 2,127 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,326 software developers and data experts.

how to write an aggregate function which can used like MAX(filedname)

Recently, I will write a database application to get the median value
according to the grouped condition.

maybe, just like the following.

SELECT Max(a1) MaxValue, Median(a1) MedianValue FROM test_table

Any suggestion?
Jul 20 '05 #1
2 2083
Hi

Check out this previous post:

http://tinyurl.com/q59j

John

"William Jiang" <wi******@qd.lucent.com> wrote in message
news:bm********@netnews.proxy.lucent.com...
Recently, I will write a database application to get the median value
according to the grouped condition.

maybe, just like the following.

SELECT Max(a1) MaxValue, Median(a1) MedianValue FROM test_table

Any suggestion?

Jul 20 '05 #2
A Google search of this group will give you several alternative median
functions depending on the exact form of median you want: Here's one
example:

CREATE TABLE SomeValues (keyx CHAR(1) PRIMARY KEY, valuex INTEGER NOT NULL)

INSERT INTO SomeValues VALUES ('A',1)
INSERT INTO SomeValues VALUES ('B',2)
INSERT INTO SomeValues VALUES ('C',3)
INSERT INTO SomeValues VALUES ('D',4)
INSERT INTO SomeValues VALUES ('E',5)

SELECT S1.valuex AS median
FROM SomeValues AS S1, SomeValues AS S2
GROUP BY S1.valuex
HAVING SUM(CASE WHEN S2.valuex <= S1.valuex
THEN 1 ELSE 0 END)
= ((COUNT(*) + 1) / 2) AND SUM(CASE WHEN S2.valuex >= S1.valuex
THEN 1 ELSE 0 END)= (COUNT(*)/2 + 1)
SQL For Smarties (Celko) has a whole chapter on how to calculate Medians in
SQL. Other statistics are also covered.
http://tinyurl.com/hntc
--
David Portas
------------
Please reply only to the newsgroup
--

"William Jiang" <wi******@qd.lucent.com> wrote in message
news:bm********@netnews.proxy.lucent.com... Recently, I will write a database application to get the median value
according to the grouped condition.

maybe, just like the following.

SELECT Max(a1) MaxValue, Median(a1) MedianValue FROM test_table

Any suggestion?

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gary | last post by:
HI, I'm facing a problem while updating a ADO recordset after modifying its records using the Dataset( ADO.Net). I'm calling a method of a COM component from C# code. The method returns a ...
1
by: gayatri_choda | last post by:
Hi, I am calling a pop -up ( a jsp page) window with the Window.open method from the parent ( a jsp page) . My pop-up window contains some input fields. Now on clicking the "Ok" button in the...
4
by: gderosa | last post by:
Hey, I've searched for a couple of days and have not found an answer. I have a textbox that needs the autocomplete/autofill feature. There are dozens of scripts out there that do this from a...
2
by: jpatchak | last post by:
I want to write an update query that updates fields from one table to another. The first table (tblCopyFrom) is in a one-to-one relationship with the 2nd (tblCopyTo). The primary key in tblCopyFrom...
5
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I guess this probably a very silly question. I am not sure if this can be done in classical asp. A button has to be clicked if a selection in drop down list has been changed. If not, a...
0
by: ssramvinay | last post by:
Hi, My TL gave me this task. If any one can able to give suggestion. plz provide asap. * We have recordset. i have one filedname called t_id(int) and cval(data type as BIT) in my emp...
2
by: Anil Gupte | last post by:
What is wrong with this? Dim strFindMax As String = "max(ProfileID)" Dim drFindMax As DataRow() = DSet.Tables("Profiles").Select(strFindMax) I get an error saying strFindMax does not evaluate...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.