Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 count distinct value(sql)

Author  Topic 

Rohit286
Starting Member

2 Posts

Posted - 2012-03-15 : 05:34:51
Hi

I have a table, in which i have to count from one field named as AirVendor but i have to count according to the distinct value of BRN(another field in the same table)

I tried this query, but dint work, plz help me out as soon as possible.

SELECT count(dbo.tbl_Flights.AirVendor ) as FltCount
FROM dbo.tbl_Flights where AirVendor in
(SELECT Distinct (BRN )
FROM dbo.tbl_Flights)
sample output of this table is
BRN AirVendor
1001 9W
1001 9W
1002 S2
1003 6E
1004 AI
1004 AI

expected output for count(Airvendor) should be 4
as BRN is repeated twice, i need to count the airvendor according to the distinct value of BRN

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-15 : 05:52:21
plz help me out as soon as possible

You should help us to help you as soon as possible!

BRN(another field in the same table)
? dbo.tbl_Flights_Details is the same as dbo.tbl_Flights ?

Please give table structure, sample data and wanted output to make it more clear.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Rohit286
Starting Member

2 Posts

Posted - 2012-03-15 : 06:26:37
hi i have added all the information and corrected my question, which u ahd asked me to do. plz reply me back.



thanks for ur response
Go to Top of Page
   

- Advertisement -