Thread: SQl query
If I've a transport table like this:transporttype | transportid ---------------+-------------Lorry | 1037Pickup | 1038Lorry | 1040Lorry | 1045Pickup | 1046Lorry | 1047 How do I make a query so that I get a result like transporttype | #of transport ---------------+-------------Lorry | 4Pickup | 2
Hi Abdul, > How do I make a query so that I get a result like > > transporttype | #of transport > ---------------+------------- > Lorry | 4 > Pickup | 2 SELECT transporttype, count(*) FROM transport GROUP BY transporttype; Cheers Matthew.
* Abdul Wahab Dahalan <wahab@mimos.my> [07.05.2003 11:52]: > If I've a transport table like this: > transporttype | transportid > ---------------+------------- > Lorry | 1037 > Pickup | 1038 > Lorry | 1040 > Lorry | 1045 > Pickup | 1046 > Lorry | 1047 > > How do I make a query so that I get a result like > > transporttype | #of transport > ---------------+------------- > Lorry | 4 > Pickup | 2 selecttransporttype,count(transporttype) fromyour_table group bytransporttype; -- Victor Yegorov
Hello, here is a suggestio: select transporttype, count(transportid) as number of transport from transport group by transporttype; @+ Walid Le Mercredi 7 Mai 2003 10:20, vous avez écrit : > If I've a transport table like this: > transporttype | transportid > ---------------+------------- > Lorry | 1037 > Pickup | 1038 > Lorry | 1040 > Lorry | 1045 > Pickup | 1046 > Lorry | 1047 > > How do I make a query so that I get a result like > > transporttype | #of transport > ---------------+------------- > Lorry | 4 > Pickup | 2 > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> How do I make a query so that I get a result like > > transporttype | #of transport > ---------------+------------- > Lorry | 4 > Pickup | 2 => select transporttype, count(transporttype) as "#of transport" from transport group by 1; regards, bhuvaneswaran