|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Select 2 counts of 2 sums
Hi,
I have 2 tables: Article(articleNb, name, qtyInStock) Order(orderNb, articleNb, qtyOrdered) I have to select the number of articles for which the total ordered quantity > 5 and the number of articles for which the total ordered quantity < 2. I can do it in 2 separate queries but I have to do it in 1 query. select count(*) AS NbPopularArticles from (SELECT SUM(qtyOrdered) FROM Article LEFT OUTER JOIN Order ON Article.articleNb = Order.articleNb GROUP BY Article.articleNb HAVING sum(qtyOrdered) > 5); select count(*) AS NbNotPopularArticles from (SELECT SUM(qtyOrdered) FROM Article LEFT OUTER JOIN Order ON Article.articleNb = Order.articleNb GROUP BY Article.articleNb HAVING sum(qtyOrdered) < 2 or sum(qtyOrdered) is NULL); Any help would be appreciated Thanks |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Select 2 counts of 2 sums |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|