MySQL - Query Questions

Hi Guys

I'm using the CASE function in the query below.

 SELECT
  from_unixtime(b.`date_create`) AS 'Booking  Date'
  ,from_unixtime(b.`timeslot`)   AS 'Allocated Date & Time Slot'
  ,b.`minutes`                   AS 'Minutes'
  ,b.`voucher_title`             AS 'Product Name'
  ,b.`customer_name`             AS 'Customer Name'
  ,from_unixtime(c.`birthdate`)  AS 'Customer DOB'
  ,c.address                               AS 'Address'
  ,c.city                                   AS 'City'
  ,c.postal_code                         AS 'Post Code'
  ,c.email                                 AS 'Customer Email'
  ,b.`customer_num`              AS 'Guest Number'
  ,b.`invoice_id`                AS 'Invoice Number'
  ,i.total_ht                                AS 'Gross'
  ,i.total_tva                             AS 'Tax'
  ,i.paid_ttc                               AS 'Total Received'
  ,i.origin                                     AS 'Bookig Method'
  ,(CASE WHEN b.checkin <- 1 THEN "Un-Finalized"
         WHEN b.checkin > 1  THEN "Finalized"
    END)                         AS Finalized
 
  FROM `booking` b
  JOIN customers c ON c.customer_num = b.customer_num
  JOIN invoices  i ON i.id                   = b.invoice_id

The table "checkin" has either a 0 or a 10 digits, such as 1515663909. What I'm trying to achieve is below

IF b.checkin < 0 THEN Un-Finalized
IF b.checkin > 0 THEN Finalized

I'm able to run the query above but I don't feel the CASE function works, any ideas?

Thanks All!
Stevie ZakhourAsked:
Who is Participating?
 
Ryan ChongCommented:
IF b.checkin < 0 THEN Un-Finalized

you should have condition of IF b.checkin = 0 THEN Un-Finalized since your value can't go below 0.

so just try:

(CASE WHEN b.checkin =0 THEN "Un-Finalized" else "Finalized"  END) AS Finalized

Open in new window

0
 
PortletPaulfreelancerCommented:
no points pl:

or you could reverse the bove

(CASE WHEN b.checkin > 0 THEN "Finalized" else "Un-Finalized"  END) AS Finalized

Open in new window

0
 
Stevie ZakhourAuthor Commented:
Awesome, that worked! Thanks Ryan!!!
0
 
Stevie ZakhourAuthor Commented:
Thanks All for Helping!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.