Conditional Aggregation

Database
Enthusiast

Conditional Aggregation

Hi All,

 

I currently have a table:

 

City

Drive

Pub_Tran

A

50

75

A

30

95

A

20

75

A

80

65

B

60

55

C

40

25

C

30

15

D

10

45

D

60

35

D

100

55

 

I am looking to provide a total of those who drive and those who take public transport for each city

 

So the end result would look like:

City

Drive

Pub_Trans

A

180

310

B

60

55

C

70

40

D

170

135

 


Accepted Solutions
Teradata Employee

Re: Conditional Aggregation

Well, the answer is kinda straightforward :

  select City
       , sum(Drive)    as Drive
       , sum(Pub_Tran) as Pub_Tran
    from MyTable
group by City
order by City
1 ACCEPTED SOLUTION
2 REPLIES
Teradata Employee

Re: Conditional Aggregation

Well, the answer is kinda straightforward :

  select City
       , sum(Drive)    as Drive
       , sum(Pub_Tran) as Pub_Tran
    from MyTable
group by City
order by City
Enthusiast

Re: Conditional Aggregation

Brain fart haha