Wrox Programmer Forums Calculate sum and skewness
 | Search | Today's Posts | Mark Forums Read
 SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
July 19th, 2003, 10:41 PM
 Registered User Join Date: Jul 2003 Location: , , Bangladesh. Posts: 8 Thanks: 0 Thanked 0 Times in 0 Posts
Calculate sum and skewness

Dear All

How can I calculate sum and skewness using same sql statement.

Regards.

July 20th, 2003, 06:03 AM
 Friend of Wrox Join Date: Jun 2003 Location: Hudson, MA, USA. Posts: 839 Thanks: 0 Thanked 1 Time in 1 Post

Calculating the sum of a set of rows is easy to do using the SUM aggregate function. SQL Server has a couple of a statistical aggregate functions which will calculate the standard deviation or variance of a column value in a set of rows. As I understand skewness. there are many different definitions of skewness depending on the distribution of the data. Some of these calculations are easy, some are quite difficult (involving integrals). Such calculations are beyond the scope of a database management system and a data manipulation language like SQL.

You should do such calculations in your client.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
July 21st, 2003, 04:25 AM
 Registered User Join Date: Jul 2003 Location: , , Bangladesh. Posts: 8 Thanks: 0 Thanked 0 Times in 0 Posts

I want to calculate sum(fieldname) and the summation of (fieldname-AVG(fieldname))/STDEV(fieldname). How I can do that using same SQL statement.

Quote:
 quote:Originally posted by Jeff Mason  Calculating the sum of a set of rows is easy to do using the SUM aggregate function. SQL Server has a couple of a statistical aggregate functions which will calculate the standard deviation or variance of a column value in a set of rows. As I understand skewness. there are many different definitions of skewness depending on the distribution of the data. Some of these calculations are easy, some are quite difficult (involving integrals). Such calculations are beyond the scope of a database management system and a data manipulation language like SQL. You should do such calculations in your client. Jeff Mason Custom Apps, Inc. www.custom-apps.com
July 21st, 2003, 05:45 AM
 Friend of Wrox Join Date: Jun 2003 Location: Hudson, MA, USA. Posts: 839 Thanks: 0 Thanked 1 Time in 1 Post

You really want to do this in your client.

The only way I can see to do this is with a bunch of subqueries:
Code:
```SELECT SUM(YourField), SUM(YourField-TheAve)/(SELECT STDEV(YourField) FROM YourTable)
FROM (SELECT YourField, (SELECT AVG(Amount) FROM YourTable) AS TheAve
FROM YourTable) AS TheData```
This will get hideous fast as the complexity (JOINS, WHERE clauses, etc.) of the base query increases. Not to mention probably slow. Do it in the client. :)

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com

 Similar Threads Thread Thread Starter Forum Replies Last Post Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM Calculate ivangr Visual Basic 2005 Basics 0 April 9th, 2006 04:39 AM Help me How to calculate minhtri VB How-To 4 June 8th, 2004 04:06 PM Sum and Skewness akmhasan Oracle 2 July 20th, 2003 01:45 AM Skewness calculation in SQL statement akmhasan Oracle 0 July 13th, 2003 04:27 AM