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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting help

Status
Not open for further replies.

neilmurray

Technical User
Jan 18, 2005
32
GB
Hi,

Supposing I have a database with customer and number of items wanted as 2 columns. If I have 1000 items to sell how would I find out at which customer is my 1000 items sold. i.e.

Customer number
1 100
2 500
3 300
4 200
5 600

Here I would only be able to supply up to customer 4. Is there any quick syntax to find this out automatically?

Thanks,

Neil.
 
How about:
[tt]
set @n:=0;

select customer
from (select customer,@n:=@n+number n from tbl1) q
where n>=1000
order by n limit 1
[/tt]
You might have to run this as two separate queries, depending on your programming interface.
 
Sorry, that should have been:
[tt]
set @n:=0;

select customer
from
(
select customer,@n:=@n+number n
from tbl1
order by customer
)
q
where n>=1000
order by n limit 1
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top