473,486 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create 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 2478
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.comwrote:
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
2656
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...
3
1574
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...
7
2342
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...
9
1195
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...
7
2158
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....
11
5523
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" +...
4
1316
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...
0
5518
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...
5
2365
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...
9
2713
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...
0
6964
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
7123
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
7175
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...
1
6842
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
7319
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...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.