472,973 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,973 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 2715
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.