learncode
learncode

Reputation: 23

How to display only the negative values, and make all the positive values display as 0?

I have written a query to display this data, the last column gives data by using this query.

TIMESTAMPDIFF(MINUTE,booking_activity.activity_time,booking.pick_up_time) AS ActualWaitingTime

Now, I have to only display the negative values, and all the positive values should become 0.

How should this query be edited?

Upvotes: 0

Views: 575

Answers (2)

Mr Deans
Mr Deans

Reputation: 369

you can use the CASE function to make anything greater than or equal to zero as zero

or alternatively in your WHEN clause to only return values less than zero

Upvotes: 0

HoneyBadger
HoneyBadger

Reputation: 15140

Try:

CASE
     WHEN TIMESTAMPDIFF(MINUTE,booking_activity.activity_time,booking.pick_up_time) < 0 
          THEN TIMESTAMPDIFF(MINUTE,booking_activity.activity_time,booking.pick_up_time)
     ELSE 0
END AS ActualWaitingTime

Upvotes: 1

Related Questions