Re: Counting things with SQL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>


.



Relevant Pages

  • Re: Pick query languages compared to SQL
    ... stored in the database ... British Expat would pay to buy a FarEastern-style basket of goods in ... That's not a problem when I'm asked to go to our customer ... New York" or even "a Brit buying a european basket in New York". ...
    (comp.databases.pick)
  • arrays and mySQL querys
    ... I can't get an $arrayto be used as a select query on a mySQL database. ... At the bottom of the table is a submit to basket Button ...
    (comp.lang.php)
  • Re: One SQL, two conns
    ... tables within cart database. ... > I'm writing an ASP cart and hit a problem. ... > Cart contents holds the unique ID from products when you do your 'basket'. ... > When I display the basket, I want to display the products name from the ...
    (microsoft.public.inetserver.asp.general)
  • Counting things with SQL
    ... I have a database with a table of basket names and a table of items in those ... I would like to find the size of the basket with the most items in. ... Andrew ... Prev by Date: ...
    (microsoft.public.sqlserver.msde)
  • Re: Counting things with SQL
    ... > Inner join [Order Details] OD ... > Count All Orders Group by the OrderID ... is the Northwind database available to those of us who only have MSDE ...
    (microsoft.public.sqlserver.msde)