sql - select repeat visitors given two time periods -


I would like to find the percentage of repeat visitors on my site. Currently I am selecting users for one month and dividing that month from next month. Is it the best way to write this question to calculate the returnees?

Generates the result that looks right, but thinks if there is a more elegant solution.

  from the SELECT table (table 'user') in the form of the total table where the table. Event IN ('event1', 'event2', 'event3') and table WHERE table.event IN ('event1', 'event2', 'event3') and table ('in the month (October') in the form of the month ('October') / (SELECT COUNT (table.user) newTotal. ) Or table. Month ('november')) AS percent_ return   

The table structure looks like this, you have only one month for the same user or many of the same time period Buy event. order_number User Month Event Gross 1 Jack October Event 2 30 2 Jack November Event 3 20 3 Jack November Event 3 20 4 Jack N Mercury event 2 30 5 Sam November Event 2 30 6 Zone October Event 3 20 7 Zone October Non-Event 20

class = "post-text" itemprop = " text ">

You do not need two subqueries that you want. Just use conditional aggregation:

  SELECT (SUM (s.manth IN (october)) / SUM ( WHERE s.event IN ('event1', 'event2', 'event3') and s.gross & gt; 0;   

In addition, a single quote is not required around the numerical constant.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -