tags:

views:

40

answers:

3

I have the following table:

mysql> SELECT * FROM consumer1;

Service_ID | Service_Type | consumer_feedback 
-----------------------------------------------
     31      Printer           -1 
     34      Printer            0 
     31      Printer            0 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 
     34      Printer            1 

I need a query such that I need THE COUNT(Service_ID)=2 AS Service_ID is 31 and 34. Please help me and give me some suggestions.

A: 
select count(distinct Service_ID) from consumer1;
Alex Martelli
+1  A: 

You can do:

SELECT COUNT(DISTINCT Service_ID) FROM consumer1
  • DISTINCT will extract all the distinct values of the field Service_ID. In your case it will return 31,34
  • COUNT will count the number of number of such values. In your case it will return 2.
codaddict
A: 

select count(*) from customer1 where Service_ID=31

Arivu2020