Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Help SQL


Message #1 by Liming Xu <lmxu@w...> on Fri, 23 Feb 2001 13:58:45 -0500
I think, the following sql helps you to solve the problem...

select min(id) id, count(cost) cnt, min(cost) cost
from ticket
group by id, amount

and result set as follows

id        cnt       cost
------------------------
1          2         10
1          1          9
1          3          8
2          1         11
2          4          8
... ...

> Hello, I need a little help with SQL statment..  I have a table 
called "ticket"
> and inside this table I have a column called "TicketID" and "ticketcost"
> 
> Now, any TicketID could have many differnt prices.. say TicketID 1 could 
have 4
> differnt price, TicketID 2 could have 5 diffent prices and etc....
> 
> how do I write  a SQL stament which shows how many different prices are 
there for
> each TicketID?
> 
> Examp
> TicketID           TicketCost
> 1                        $10
> 2                        $9
> 1                        $15
> 2                        $8
> 1                        $10
> 2                        $7
> 1                        $15
> 
> so the sql statemnt should return in this example    TiketID1  has two 
$10, two
> $15, Ticekt ID2 has one $9, one $8, one $7
> 
> do I group by "TicketCost" first and then do a Count(TiketID) or?????
> 
> thanks...
> 
> 
> 

  Return to Index