473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with logic

Hello all,

This is probably not related to db2 but due to fabulous responses i
got earlier for my questions, i am convinced that this forum is full
of smart people.

Here is question:

I have data rows say count of 3000 which i got from sql. i call this
universe.
Now i need samples out of this universe. say my sample size is 45.
this is for audit and samples are random rows picked from universe. i
can use random functions but business people does not want it that
random. so i divide universe by sample and start from first row of
universe skipping universe/sample rows and created a sample. There are
more complications to it but not relevant here. My questions is if
there is some statistical/mathematical formula or way to do this
same thing say pick rows from large dataset which are equally
distributed ( i might not be using the right term "equally
distributed").

Regards,
udbadmin

Mar 21 '07 #1
8 2487
db2admin wrote:
Hello all,

This is probably not related to db2 but due to fabulous responses i
got earlier for my questions, i am convinced that this forum is full
of smart people.

Here is question:

I have data rows say count of 3000 which i got from sql. i call this
universe.
Now i need samples out of this universe. say my sample size is 45.
this is for audit and samples are random rows picked from universe. i
can use random functions but business people does not want it that
random. so i divide universe by sample and start from first row of
universe skipping universe/sample rows and created a sample. There are
more complications to it but not relevant here. My questions is if
there is some statistical/mathematical formula or way to do this
same thing say pick rows from large dataset which are equally
distributed ( i might not be using the right term "equally
distributed").
I believe you want this:

SELECT ...
FROM ( SELECT ..., row_number() over(...) AS rn
FROM ... ) AS t
WHERE rn = universe/sample

Note that you will have to provide an ordering criterion in the OVER(...)
clause. Otherwise, you get an arbitrary order/numbering, and then you
could use RAND() as well:

SELECT ...
FROM ( SELECT ..., RAND() AS rnd
FROM ... ) AS n
ORDER BY rnd
FETCH FIRST sample ROWS ONLY

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mar 21 '07 #2
db2admin wrote:
Hello all,

This is probably not related to db2 but due to fabulous responses i
got earlier for my questions, i am convinced that this forum is full
of smart people.

Here is question:

I have data rows say count of 3000 which i got from sql. i call this
universe.
Now i need samples out of this universe. say my sample size is 45.
this is for audit and samples are random rows picked from universe. i
can use random functions but business people does not want it that
random. so i divide universe by sample and start from first row of
universe skipping universe/sample rows and created a sample. There are
more complications to it but not relevant here. My questions is if
there is some statistical/mathematical formula or way to do this
same thing say pick rows from large dataset which are equally
distributed ( i might not be using the right term "equally
distributed").
In addition to Knuts response, this might fit your needs:

select * from T tablesample system (x)

or

select * from T TABLESAMPLE BERNOULLI(x)
See: http://tinyurl.com/2sd77b
/Lennart

Mar 21 '07 #3
Knut Stolze wrote:
[...]
I believe you want this:

SELECT ...
FROM ( SELECT ..., row_number() over(...) AS rn
FROM ... ) AS t
WHERE rn = universe/sample
But this will only return 1 row, should it not be something like:

WHERE mod(a*rn,b) = 0
/Lennart

Note that you will have to provide an ordering criterion in the OVER(...)
clause. Otherwise, you get an arbitrary order/numbering, and then you
could use RAND() as well:

SELECT ...
FROM ( SELECT ..., RAND() AS rnd
FROM ... ) AS n
ORDER BY rnd
FETCH FIRST sample ROWS ONLY
Mar 21 '07 #4
Lennart wrote:
[...]
>
See: http://tinyurl.com/2sd77b
Beats me why the url didnt work. Here is another shot:

http://publib.boulder.ibm.com/infoce...28%31%29%22%20

/Lennart

Mar 21 '07 #5
Lennart wrote:
Knut Stolze wrote:
[...]
>I believe you want this:

SELECT ...
FROM ( SELECT ..., row_number() over(...) AS rn
FROM ... ) AS t
WHERE rn = universe/sample

But this will only return 1 row, should it not be something like:

WHERE mod(a*rn,b) = 0
Yes, of course...

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mar 22 '07 #6
On Mar 22, 5:14 am, Knut Stolze <sto...@de.ibm. comwrote:
Lennart wrote:
Knut Stolze wrote:
[...]
I believe you want this:
SELECT ...
FROM ( SELECT ..., row_number() over(...) AS rn
FROM ... ) AS t
WHERE rn = universe/sample
But this will only return 1 row, should it not be something like:
WHERE mod(a*rn,b) = 0

Yes, of course...

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Thanks for all this help
I get error message when i try to use tablesample BERNOULLI function

SQL0270N Function not supported (Reason code = "43"). SQLSTATE=42997

here is output from db2level

DB21085I Instance "ABCD" uses "64" bits and DB2 code release
"SQL08025"
with level identifier "03060106".
Informational tokens are "DB2 v8.1.1.112", "s060429", "U807381", and
FixPak
"12".
Product is installed at "/usr/opt/db2_08_01".

when i look at help
reason code 43 is

43 Please reissue the runstats command and set the unsupported
option off.

How to reissue runstats command with unsupported option off

Regards,
udbadmin

Mar 22 '07 #7
On Mar 22, 2:17 pm, "db2admin" <jag...@gmail.c omwrote:
On Mar 22, 5:14 am, Knut Stolze <sto...@de.ibm. comwrote:
Lennart wrote:
Knut Stolze wrote:
[...]
>I believe you want this:
>SELECT ...
>FROM ( SELECT ..., row_number() over(...) AS rn
> FROM ... ) AS t
>WHERE rn = universe/sample
But this will only return 1 row, should it not be something like:
WHERE mod(a*rn,b) = 0
Yes, of course...
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

Thanks for all this help
I get error message when i try to use tablesample BERNOULLI function

SQL0270N Function not supported (Reason code = "43"). SQLSTATE=42997

here is output from db2level

DB21085I Instance "ABCD" uses "64" bits and DB2 code release
"SQL08025"
with level identifier "03060106".
Informational tokens are "DB2 v8.1.1.112", "s060429", "U807381", and
FixPak
"12".
Product is installed at "/usr/opt/db2_08_01".

when i look at help
reason code 43 is

43 Please reissue the runstats command and set the unsupported
option off.

How to reissue runstats command with unsupported option off

Regards,
udbadmin
I figured it out
I was trying to use tablesample BERNOULLI function on another
subselect and db2 cries for that
table should be solid table like real table, MQT or DTT
i put contents of subselect in DTT and used tablesample on DTT. I
worked fine

thanks to everyone for great help

regards,
jagdip singh

Mar 22 '07 #8
Here is an implementation of the additive congruential method of
generating values in pseudo-random order and is due to Roy Hann of
Rational Commerce Limited, a CA-Ingres consulting firm. It is based
on a shift-register and an XOR-gate, and it has its origins in
cryptography. While there are other ways to do this, this code is
nice because:

1) The algorithm can be written in C or another low level language for
speed. But math is fairly simple even in base ten.

2) The algorithm tends to generate successive values that are
(usually) "far apart", which is handy for improving the performance of
tree indexes. You will tend to put data on separate physical data
pages in storage.

3) The algorithm does not cycle until it has generated every possible
value, so we don't have to worry about duplicates. Just count how
many calls have been made to the generator.

4) The algorithm produces uniformly distributed values, which is a
nice mathematical property to have. It also does not include zero.

Generalizing the algorithm to arbitrary binary word sizes, and
therefore longer number sequences, is not as easy as you might think.
Finding the "tap" positions where bits are extracted for feedback
varies according to the word-size in an extremely non-obvious way.
Choosing incorrect tap positions results in an incomplete and usually
very short cycle, which is unusable. If you want the details and tap
positions for words of one to 100 bits, see E. J. Watson, "Primitive
Polynomials (Mod 2)", Mathematics of Computation, v.16, 1962, p.
368-369. Here is code for a 31-bit integer, which you can use:

see the details at:

http://www.rationalcommerce.com/reso...surrogates.htm

UPDATE generator31
SET keyval
= keyval/2 + MOD(MOD(keyval, 2) + MOD(keyval/2, 2), 2) * 8;

Mar 23 '07 #9

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

Similar topics

6
2661
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a string of the form 100...0 using an arbitrary (but finite) number of zeros. Prove by induction that this transformation can not be performed...
3
1581
by: Mike | last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working on this for the past 4 days and nothing I do seems to get me any closer to the solution. Below is a program that I am working on for a class project. The original code was provided for us which...
7
2348
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I...
9
1201
by: Jack Addington | last post by:
I have a base form and a base logic class. Each has to know of the other. I'm then inheriting to create descendant form and descendant logic which extend both objects and again have to know of each other. I'm getting mixed up in the syntax/technique on how to refer to the references generically in the code. I want to be able to always call...
7
2161
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require. Below is the script I currently use and what it does along with what I would like it to do. Can someone please help me work how I can fix this. ...
11
5535
by: ricolee99 | last post by:
Hi everyone, I'm trying to invoke my .exe application from a remote server. Here is the code: ManagementClass processClass = new ManagementClass ("\\\\" +"RemoteServerName" + "\\root\\CIMV2:Win32_Process");
4
1319
by: John Sitka | last post by:
Hi, sorry for a crosspost but that other news group was showing last post was a week ago so I guess it dosen't see much use... I'm about to start a solution and I'm curious about the approach of a webservices project. Should the objects be represented in classes such as... public class Orders (ie Orders.cs) within a project and then have...
0
5536
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
5
2370
by: Burt | last post by:
There's an architect at my 200 person company that advocates having many layers in all my C# apps. He wants web services, use case handlers, facade layers, data gateways, etc. When I ask why all this complexity is necessary, he gives me what if scenarios: "What if you ever want to access the business logic with another front end?", for...
9
2722
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic in. My business classes are, of course, decorated with the: <System.ComponentModel.DataObject() attribute. So, I drop a GridView on a webform...
0
7526
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7457
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7965
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6051
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5375
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.