0

I am facing an issue with where the table structure is as below

SHIPMENT_GID || COST_TYPE || COST
12233        ||B          ||1180
12234        ||B          ||1300
12235        ||B          ||1100
12236        ||B          ||1400
12233        ||B          ||200
12233        ||A          ||300

Here I want is the SQL query should fetch me unique shipment Id that has Count(cost_type = B) >1

I had the following query but it is not working

select * from shipment_cost where shipment_gid = (select SHIPMENT_GID 
                                                  from shipment_cost 
                                                  where (count(COST_TYPE = 'B')>1)
Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
mrugen munshi
  • 3,497
  • 9
  • 36
  • 50

1 Answers1

4

This should do it:

 SELECT SHIPMENT_GI, count(*)
 FROM shipment_cost
 WHERE COST_TYPE='B' 
 GROUP BY SHIPMENT_GI
 HAVING COUNT(*) > 1
Ankit Bajpai
  • 13,128
  • 4
  • 25
  • 40
Bruce
  • 1,542
  • 13
  • 17