Normalizing a MYQL database
Ruslan Zasukhin
sunshine at public.kherson.ua
Fri Jan 5 02:57:40 CST 2007
On 07/5/1 1:28 AM, "Robert Mann" <robmann at gp-racing.com> wrote:
> Ok did some searching on "transpose columns into rows"
> There seems to be some way of doing this using SQL but it is above my sql
> knowledge, I found this example I just don't know how to change to input the
> columns into a new table anyone know how to do this? I would prefer to have
> the new table created by this same sql statement if possible.
>
> ----------------------------
> ID Attribute Value
> ----------------------------
> 10 username user1
> 10 password pass1
> 11 username user2
> 11 password pass2
> ---------------------------
>
> I want to rotate this table as follows:
> --------------------------------
> ID username password
> --------------------------------
> 10 user1 pass1
> 11 user2 pass2
> --------------------------------
>
> Select T1.ID, T1.Value as UserName, T2.Value as Password from TableName T1
> Inner Join TableName T2 On T1.ID = T2.ID And T2.Attribute = 'password'
> Where T1.Attribute = 'username'
Take a look at this URL
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21178948.ht
ml
And comment at middle of page:
--------------
If I was doing it in SQL, I'd do it something like this:
insert table2
select product, date 1 from table1
insert table2
select product, date 2 from table1
insert table2
select product, date3 from table1
That would normalize your data for you, which is basically what you're
trying to do. Then you could select from table2 for the final result set.
--------------
Then they discuss how they can automate this in loop.
You also can try write some script to automate at first group of columns
with name 'ddd' then group with name 'gggg'.
--
Best regards,
Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc
Valentina - Joining Worlds of Information
http://www.paradigmasoft.com
[I feel the need: the need for speed]
More information about the Valentina
mailing list