Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Conditional COUNT() ?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00918618
Message ID:
00919628
Vues:
10
>How do I create an SQL statement that has a count of all records, plus a conditional count of the number that meet a specific criteria?
>
>This gives me the count(*) value twice.
>
>SELECT OrderID, COUNT(*), COUNT(Lineitems.Quantity > 500) 
  FROM Orders INNER JOIN Lineitems on Lineitems.orderid = Orders.orderid
  GROUP BY 1
>
>
>Once that works, will using a view parameter(?vp_bonusamount) work instead of the fixed numeric amount?
>
>Chris.

I may have misunderstood what you are counting, but here is a pair of queries that returns one value, using a parameter:

m.bonus = whatever

SELECT OrderID, Count(*) AS counted FROM Lineitems INTO CURSOR prelim NOFILTER HAVING Count(*) >= m.bonus GROUP BY OrderID

SELECT Count(*) AS countmorethan FROM prelim INTO CURSOR results
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform