Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditional COUNT() ?
Message
From
29/06/2004 15:29:05
 
 
To
29/06/2004 15:21:01
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00918618
Message ID:
00918620
Views:
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,

Something like this will work...
SELECT OrderID, COUNT(*), sum(iif(lineItems.quantity > 500, 1, 0)) as bigQuantity ;
   FROM Orders  ;
   INNER JOIN Lineitems on Lineitems.orderid = Orders.orderid ;
   GROUP BY 1
Yes, the 500 can be a view parameter.
Steve Gibson
Previous
Reply
Map
View

Click here to load this message in the networking platform