Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL to normalize the data!
Message
De
21/07/1999 21:53:24
 
 
À
21/07/1999 12:57:24
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00243953
Message ID:
00244511
Vues:
16
Thanks all of you!

I learn much more, it is hard to give a good if the raw data give so poor duplicate data

Anyway, group by in very powerful in SQL, if the data is grouped much.

>As John said, you have more of a cross-tab than a fully normalized table. But I understand that that wasn't you point. You can do this with a query if the types of coins is fixed:
>
>SELECT studentid, studname,
>SUM(IIF(coins = '1', qty, 0)) AS 1_Dollar,
>SUM(IIF(coins = '2', qty, 0)) AS 2_Dollar,
>SUM(IIF(coins = '5', qty, 0)) AS 5_Dollar,
>SUM(IIF(coins = '10', qty, 0)) AS 10_Dollar
>FROM badtable
>GROUP BY studentid, studname
>ORDER BY studentid
>
>-Mike
>
>>One friend ask me how to convert the non-normalize dbf to standard!
>>
>>
>>badtable:
>>
>>StudentID    StudName    Coins      Qty
>>-----------------------------------------
>>PJ00001      May         5_Dollar    10
>>PJ00001      May         2_Dollar     4
>>PJ00002      John        10_Dollar    6
>>PJ00002      John        2_Dollar     5
>>PJ00002      John        1_Dollar     3
>>PJ00003      Peter       5_Dollar     7
>>PJ00003      Peter       1_Dollar    15
>>PJ00004      Susan       10_Dollar    2
>>PJ00004      Susan       5_Dollar     1
>>...
>>
>>
>>GoodTable:
>>
>>StudentID    StudName    1_Dollar  2_Dollar  5_Dollar  10_Dollar
>>-----------------------------------------------------------------
>>PJ00001      May            0         4         10         0
>>PJ00002      John           3         5          0         6
>>PJ00003      Peter         15         0          7         0
>>PJ00004      Susan          0         0          1         2
>>........
>>
>>
>>
>>
>>For Report, simply use group can do it, but how to change the table
>>into this structure na!?
>>
>>Thanks!
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform