Second Most (Not so TOP)

  • Data manipulation for the number 2
  • Looking out for number 1 is easy with Top or Max.
  • This query finds number 2.

Pivot and Rank in action

  • Select Customer ID on left.
  • See the second most sales for that customer.
  • The query selects the TOP 2 sales into a Temp table.
  • A second query selects the TOP 1 sales from the Temp table sorting ascending on the sales count.
csrIDNameProductIDorderDateQty
11176Road Tire Tube92207/18/2004 7

Michael W Stark

Software Developer

.Net 3.5
SQLServer 2005 2008

Rich Interface Design

Rapid Development

Flash


My Work


SQL Samples