Re: Counting things with SQL
- From: "Jens Süßmeyer" <Jens@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 15 Apr 2005 16:35:14 +0200
Here is an example for the Northwind database, can be easely compared to
your database with the right key associated.
Select O.OrderID,Count(*) from Orders O
Inner join [Order Details] OD
On O.OrderID = OD.OrderID
Group by O.OrderIDa
Count All Orders Group by the OrderID
(Yeah newsgroupreaders, i know you can easely only count those OrderDetails,
but in this case the poster has the basketname in the 1 "Orders" Table of
the 1:n relationship)
HTH, Jens Süßmeyer
---
http://www.sqlserver2005.de
---
"Andrew Morton" <akm@xxxxxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:uOMv$VcQFHA.3356@xxxxxxxxxxxxxxxxxxxxxxx
>I have a database with a table of basket names and a table of items in
>those baskets.
> I would like to find the size of the basket with the most items in.
> I cannot figure out how to do this is T-SQL:-
>
> nMax=0
> for each basketName in basket
> n=count(records in basketItem where
> basket.basketName=basketItem.basketName)
> if n>nMax then n=nMax
> next
>
> Is there a simple way of doing it, or would it be more efficient to
> retrieve the size of each basket into an array in vb.net and figure out
> the largest one there?
>
> Andrew
>
.
- Follow-Ups:
- Re: Counting things with SQL
- From: Andrew Morton
- Re: Counting things with SQL
- References:
- Counting things with SQL
- From: Andrew Morton
- Counting things with SQL
- Prev by Date: Re: newbie question
- Next by Date: Re: I need help with SELECT statement
- Previous by thread: Counting things with SQL
- Next by thread: Re: Counting things with SQL
- Index(es):
Relevant Pages
|