How to group two values in a field in a select statement?

Database
Highlighted
Enthusiast

How to group two values in a field in a select statement?

So I have a table table 1 that I am looking to pull data from.

Typeamount
car1
truck3
boat4
house5

 

I like to pull the type car,truck and boat and group car and truck in one group called vehicle

 

my select statement would be something like this:

 

select type, amount from table 1 where (type) in('car','truck','boat)

 

I cant seem to know how to group car and truck in one group 

 

any help is appreciated


Accepted Solutions
Teradata Employee

Re: How to group two values in a field in a select statement?

Yes, wrap a select around it such as:

select 
case when type in ('car','truck') then 'vehicle' else type end
,sum(amount)
group by 1
1 ACCEPTED SOLUTION
3 REPLIES 3
Junior Contributor

Re: How to group two values in a field in a select statement?

That's a simple CASE

case when type in ('car','truck') then 'vehicle' else type end
Enthusiast

Re: How to group two values in a field in a select statement?

Thanks! do I have to add a group by statement? how would the amount field be populated? would it roll up to the group type?

Teradata Employee

Re: How to group two values in a field in a select statement?

Yes, wrap a select around it such as:

select 
case when type in ('car','truck') then 'vehicle' else type end
,sum(amount)
group by 1