Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interesting SQL Propblem 1

Status
Not open for further replies.

VVVA

Technical User
Sep 19, 2006
35
US
I've got a sql question. If I have a table that has two columns, book and page, what is the best way to get a count of all the missing pages for each book?

So, if I have this table...
Code:
Book   Page

0001   0001
0001   0002
0001   0005
0001   0006
0002   0001
0002   0005
0002   0006
0002   0009
0003   0001
0003   0002
0003   0003

I want these results....

Code:
Book   MissingPages
0001   2
0002   5
0003   0

I've managed to do this, but my code is slow, cumbersome, and I'd be better off using a cursor. Anybody have an idea of how to do this fast and elegantly?
 
OMG! Thanks a million SQLDennis...*beats head against desk*
 
...which assumes the last page(s) of each book is/are not missing.

But maybe that is not the real world problem.

Bye, Olaf.
 
Isn't the problem unsolvable if you don't have the last page?

You need that or more information (and if you had more information this would not be a problem at all)

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top