mercredi 15 juin 2016

SQL - Compare two columns find the true value and use the value in IF calculation

I am trying to compare two columns page_entry & exit_page if both true value of 1 then its a bounce.

Page_entry |  exit_page | Bounce 
    1             1        true
    0             1        false 
   etc           etc       ......

this is what I came up with and it only shows me the true values

select hit_id,visit_num,
    CASE 

        WHEN entry_page = exit_page
        THEN 'True'
        ELSE 'False'

    END as Bounce
FROM [dbo].[Primary]
WHERE entry_page = exit_page
END

BUT now I need to write a calculation like

SUM(IF Bouce = TRUE THEN 1 ELSE 0 END)/page_visit

Aucun commentaire:

Enregistrer un commentaire