Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Crosstab mania?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00242206
Message ID:
00242435
Vues:
17
>>>I have a table that looks like this:
>>>
>>>
>>><b>artnr    date</b>
>>>2        1999-04-01
>>>2        1999-05-01
>>>2        1999-05-01
>>>3        1999-04-01
>>>
>>>And I want to have make something to get something like this
>>>
>>><b>artnr    Jan     Feb     Mar     Apr     May     ...    Dec</b>
>>>2         0       0       0      1       2
>>>3         0       0       0      1       0
>>>
>>>
>>>Anyone who can give some clues how to write the SQL-command? I could problably write some code to fix it, but there ought to be some cunning SQL-phrase that would take care of it for me.
>>>
>>>/Pierre Unge, Sweden
>>
>>How about:
>>
>>SELECT artnr, ;
>> COUNT(MONTH(date)=1) AS Jan, ;
>> COUNT(MONTH(date)=2) AS Feb, ;
>> etc ;
>> FROM MyTable GROUP BY artnr
>
>Hi Fred,
>Close, but that one gives the following result
>
><b>artnr    Jan     Feb     Mar     Apr     May     ...    Dec</b>
>2         3       3       3      3       3
>3         1       1       1      1       1
>
>/Pierre

Sorry, I didn't actually try it before I sent it. I'll have to agree with Craig on this, SQL first then use VFPXTAB for the final result.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform