473,406 Members | 2,843 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.

SQL Agreate Functions

Hi,

I have a problem I dont really know how to solve except for writing a
function.

I have a table with prices;

SecCode| Price | PriceDate
-------+------------+-----------
A0001 | 13.10 | 2004-10-30
A0001 | 13.03 | 2004-10-29
A0001 | 13.12 | 2004-10-28
A0001 | 12.45 | 2004-10-27
A0001 | 12.65 | 2004-10-26
A0001 | 12.45 | 2004-10-25

A0002 | 10.10 | 2004-10-30
A0002 | 10.45 | 2004-10-27
A0002 | 10.65 | 2004-10-26
A0002 | 10.45 | 2004-10-25
etc.

What I would like to calculate is:

a) the difference of the past 2 days for every security of
available prices

b) a flag indicating, that the price of today-1 is yesterday's
price (true in case A0001, false for A0002)

c) the variance of the past 30 days
Is it possible to do that within one query?

Thanks for any advise
Alex

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
2 2409
Alex P wrote:
Hi,

I have a problem I dont really know how to solve except for writing a
function. [snip] What I would like to calculate is:

a) the difference of the past 2 days for every security of
available prices
Find the maximum date for a give SecCode (simple enough) and then the
maximum date that is smaller than the one you just found (assuming no
repetition of dates for a given SecCode).
b) a flag indicating, that the price of today-1 is yesterday's
price (true in case A0001, false for A0002)
SELECT ... (PriceDate = (CURRENT_DATE - 1)) AS is_yesterday, ...
c) the variance of the past 30 days
Variance aggregate function
Is it possible to do that within one query?


Three sub-queries and some joining, certainly. It'll be a big query
mind, perhaps worth wrapping in a function.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #2
Alex P wrote:
Hi,

I have a problem I dont really know how to solve except for writing a
function. [snip] What I would like to calculate is:

a) the difference of the past 2 days for every security of
available prices
Find the maximum date for a give SecCode (simple enough) and then the
maximum date that is smaller than the one you just found (assuming no
repetition of dates for a given SecCode).
b) a flag indicating, that the price of today-1 is yesterday's
price (true in case A0001, false for A0002)
SELECT ... (PriceDate = (CURRENT_DATE - 1)) AS is_yesterday, ...
c) the variance of the past 30 days
Variance aggregate function
Is it possible to do that within one query?


Three sub-queries and some joining, certainly. It'll be a big query
mind, perhaps worth wrapping in a function.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3

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

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
25
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.