Freelancer
Freelancer

Reputation: 9074

making simple sql query count

I have database structure like this>

ID |  Party_Code |  Trade_Qty | Market_Rate
-------------------------------------------    
 1     8070            5           10.50
 2     8745            15          80.35
 3     8070            6           45.60

This is just the sample data. Actually this table contains 40000 rows.

As from this sample we can see that Party_Code columns can have repeated values.

I am trying to find the count of distinct party codes.

For that I tried following two queries which failed:

select count(distinct(Party_Code)) from tradeFile

and

select distinct(count(Party_Code)) from tradeFile

Both of these queries failed.

I want to know where I am making mistake?

What is the way to write such queries?

Upvotes: 1

Views: 96

Answers (2)

Cody Kosmerick
Cody Kosmerick

Reputation: 83

When using the Count function, it is best to use it with a Group By clause:

select count(*) as Quantity from tradeFile Group By Party_Code

Upvotes: 0

barc0de
barc0de

Reputation: 180

select count(distinct Party_Code) from tradeFile

Upvotes: 1

Related Questions