2

I have a table with something like the following:

OrderNo, OrderType
1, Type1
2, Type1
3, Type2
4, Type3
5, Type4

Doing a "group by" on OrderType is easy but is there a way to do a "group by" to get something like:

OrderCount, OrderType
2, Type1
3, Not Type1

This is DB2 but ideally I am looking for a solution that will work regardless of DB vendor.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
Matt
  • 2,503
  • 4
  • 31
  • 46

2 Answers2

7

group by case when OrderType = 'type1' then 'type1' else 'not type 1' end

lc.
  • 113,939
  • 20
  • 158
  • 187
paul
  • 21,653
  • 1
  • 53
  • 54
1

try:

Select Case OrderType When 'Type1' Then 'Type1'
            Else 'NotType1' End OrderType, 
       Count(*) OrderCount
From Table
Group By Case OrderType When 'Type1' Then 'Type1'
              Else 'NotType1' End
Charles Bretana
  • 143,358
  • 22
  • 150
  • 216