Thread: SQl query

SQl query

From
Abdul Wahab Dahalan
Date:
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



Re: SQl query

From
Matthew Horoschun
Date:
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.



Re: SQl query

From
"Victor Yegorov"
Date:
* 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

Re: SQl query

From
DIB Walid
Date:
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)



Re: SQl query

From
"A.Bhuvaneswaran"
Date:
> 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