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

STD of multiple columns

Dear Mysql-ians,

I want to calculate the standard deviation of data that are in multiple
columns. I know how to calculate the STD of 1 column (e.g. X1 of
table_X) using:

SELECT STD(X1) FROM table_X;

but I want to calculate now the STD of the union of data of columns
(e.g. X1, X2, ..., X100 of table_X).

Does anyone has any suggestion on how to do that? I hoped something as
SELECT STD(X1,X2,...,X100) FROM table_X existed, but apparently it does
not.

Thanks for your suggestions in advance!

Kind regards,
Stef

Apr 14 '06 #1
7 2744
st***************@agr.kuleuven.ac.be wrote:
Dear Mysql-ians,

I want to calculate the standard deviation of data that are in multiple
columns. I know how to calculate the STD of 1 column (e.g. X1 of
table_X) using:

SELECT STD(X1) FROM table_X;

but I want to calculate now the STD of the union of data of columns
(e.g. X1, X2, ..., X100 of table_X).

Does anyone has any suggestion on how to do that? I hoped something as
SELECT STD(X1,X2,...,X100) FROM table_X existed, but apparently it does
not.

Thanks for your suggestions in advance!

Kind regards,
Stef


Stef,

I don't *think* it's possible from your current design.

Perhaps a redesign is in order. Having 100 columns containing basically the
same information is not a good design.

For instance, in the case of student test scores - you could do something like:

(table) studentid name test1scrore test2score test3score test4score

(Of course there would be more info)

A better design would be:

(table 1) studentid name

(table 2) studentid testid score

Such a design is more versatile - and cures your problem along the way.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 14 '06 #2
Thanks for your help!

If I look at my design, it looks like:
(table) id, obs_time1, obs_time2, ..., obs_time100
where:
obs_timeX = observation at "time X"

I have over 2 million records (with different unique id's) for this
table, and I want to create the STD of all observations of 1 id through
time.

If I understand your design well, you suggest to reform it towards:
(table_1) studentid + other info
(table_2) studentid obs_time obs_value
where:
obs_time = "time X" of obs_timeX
obs_value = value of obs_timeX with corresponding "time X"

If I am correct, I will get a very long table_2 since I create 2
millions (ids) *100 records (for every obs_time). Don't I create much
more redundant information then (having only 1 row of obs_timeX per id
and having unique id's)?

I hope i made myself clear?

Thanks again for your help!

Regards
Stef

Apr 14 '06 #3
st***************@agr.kuleuven.ac.be wrote:
Thanks for your help!

If I look at my design, it looks like:
(table) id, obs_time1, obs_time2, ..., obs_time100
where:
obs_timeX = observation at "time X"

I have over 2 million records (with different unique id's) for this
table, and I want to create the STD of all observations of 1 id through
time.

If I understand your design well, you suggest to reform it towards:
(table_1) studentid + other info
(table_2) studentid obs_time obs_value
where:
obs_time = "time X" of obs_timeX
obs_value = value of obs_timeX with corresponding "time X"

If I am correct, I will get a very long table_2 since I create 2
millions (ids) *100 records (for every obs_time). Don't I create much
more redundant information then (having only 1 row of obs_timeX per id
and having unique id's)?

I hope i made myself clear?

Thanks again for your help!

Regards
Stef


Stef,

Yep, that's exactly what I'm suggesting. Do some reading up on "Database
Normalization" - it can help you understand why this is potentially a better
solution.

And yes, the new table will be quite long. But your existing table is quite
wide! 200M rows (the max you could have) isn't as different than what you have
now - 2M rows with > 100 columns in each row.

Also, as you normalize your tables, you can potentially have more, if the
majority of the fields are filled. But you may also have less, if only a small
number are filled. And normalizing your tables makes things more flexible.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 14 '06 #4
Thanks for your suggestion! I will try to reorganize my data.

I was thinking of making a query to reorganize my data.
E.g.:
(SELECT id, "name(obs_time1)" AS obs_time, obs_time1 AS obs_value FROM
table_1)
UNION
(SELECT id, "name(obs_time2)" AS obs_time, obs_time2 AS obs_value FROM
table_1)
UNION
.......
UNION
(SELECT id, "name(obs_time100)" AS obs_time, obs_time100 AS obs_value
FROM table_1)
ORDER BY id

with:
"name(obs_timeX)"= the name of my columns I now use to extract
obs_timeX

Hopefully that will work!

Regards,
Stef

Apr 14 '06 #5

Stef,

do you really want to run a union of 100 select on a table with 2
millions records ?!?

Actually I don't see where is the problem, why dont' you just apply the
function std to each single column, select std(v1), std(v2), ... ? Why
do you feel you need a multivariate function?

-tom

st***************@agr.kuleuven.ac.be ha scritto:
Thanks for your suggestion! I will try to reorganize my data.

I was thinking of making a query to reorganize my data.
E.g.:
(SELECT id, "name(obs_time1)" AS obs_time, obs_time1 AS obs_value FROM
table_1)
UNION
(SELECT id, "name(obs_time2)" AS obs_time, obs_time2 AS obs_value FROM
table_1)
UNION
......
UNION
(SELECT id, "name(obs_time100)" AS obs_time, obs_time100 AS obs_value
FROM table_1)
ORDER BY id

with:
"name(obs_timeX)"= the name of my columns I now use to extract
obs_timeX

Hopefully that will work!

Regards,
Stef


Apr 14 '06 #6
st***************@agr.kuleuven.ac.be wrote:
Thanks for your suggestion! I will try to reorganize my data.

I was thinking of making a query to reorganize my data.
E.g.:
(SELECT id, "name(obs_time1)" AS obs_time, obs_time1 AS obs_value FROM
table_1)
UNION
(SELECT id, "name(obs_time2)" AS obs_time, obs_time2 AS obs_value FROM
table_1)
UNION
......
UNION
(SELECT id, "name(obs_time100)" AS obs_time, obs_time100 AS obs_value
FROM table_1)
ORDER BY id

with:
"name(obs_timeX)"= the name of my columns I now use to extract
obs_timeX

Hopefully that will work!

Regards,
Stef


Stef,

Actually, I think I'd do it in PHP or some other language and let it loop, i.e.

(Assuming you're using a version which can insert from a select statement)

for ($i = 1; $i <= 100; $i++) {
$query = "INSERT INTO newtable (studentid, obs_time, obs_value) " .
"VALUES (SELECT studentid, $i, obs_value" . $i , ") FROM oldtable";
result = mysql_query($query);
if (!$result) {
echo "MySQL Error: " . mysql_error();
break;
}
}

Also, if all of the times don't have values and you don't need to insert them,
you can do this in two queries - select the value; if it's null (or blank) then
you don't need to insert it into the new table.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 15 '06 #7
Thanx Jerry. I followed your advice and it worked wonderfully!

Apr 25 '06 #8

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

Similar topics

1
by: Nikola Pecigos | last post by:
Hi, I have the following problem: We have an Oracle 9.2 with one table "document" which contains a path to the filesystem. If I want to index these files (HTML, PDF, World, Excel, etc.), I...
4
by: Bob Hotschins | last post by:
I've joined several columns from several tables, and I would like to perform a relevance match against these multiple columns. It looks something like this: SELECT * FROM table1 LEFT JOIN...
6
by: Dennis | last post by:
In CSS3 it looks like we'll have multiple column flowing of text (newspaper style) in which the number of columns can be determined automatically given the available horizontal space....
7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
2
by: BF | last post by:
Hi, I have some tables where I import data in, lots of field have gotten a NULL value which the application can not handle. Now can I replace each NULL value with '' in a columns with: update...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
2
by: ray well | last post by:
i need to display 2 columns of data in a list box. how would i set this up IN CODE. say my table is tblNames, and i have 2 fields, FirstName, LastName, and want the data to show up in 2...
3
by: Will | last post by:
Can someone help with code to delete multiple columns from an excel spreadsheet? I know which columns I need to delete. The code below will delete a single column but I'm not sure how to delete...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
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,...
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.