Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
COUNT() Function
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01114075
Message ID:
01114093
Vues:
19
There's a big difference between 'works' and 'produces correct result'. The VFP query doesn't guaranty that result will be correct under all conditions because non-grouped, non-aggreagate fields are comming from the last phisycal record in a group. You can use MAX() function if you want the highest ID. See corrections inline.

>Ok, now I'm getting results, but it's not what I want. This works in my VFP version.
>
>Here's what I'm getting back:
>
>
SELECT MAX(r.id) AS ID,
>       r.transaction_date,
>       0 as batchid,
>       r.telemrkt_company,
>       t.company_code,
>       count(*) as Cnt
>FROM result_detail r
>JOIN telemrkt_company t on r.telemrkt_company = t.id
GROUP BY r.transaction_date, r.telemrkt_company, t.company_cod
>
>
>1	2006-01-03 00:00:00.000	0	135	WEST	1
>2	2006-01-03 00:00:00.000	0	135	WEST	1
>3	2006-01-03 00:00:00.000	0	135	WEST	1
>4	2006-01-03 00:00:00.000	0	135	WEST	1
>5	2006-01-03 00:00:00.000	0	135	WEST	1
>
>
>Problem is, I need back one record with a count of 5. Because the Id is required, the
>records are not grouped into one.
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform