Click here to Skip to main content
16,021,757 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi guys,
I´m new to MySQL , so I would need some help. I´m writing my master thesis where I need to use SQL statements in order to get data from MySQL into a visualization software (software is called tableau) but I´m totally swamped :( would really appreciate your help!! Thanks a lot in advance! Best, Désirée
Here is my question: how do I get the following 4 calculations in one SQL statement:
• Database: is called foto
• The table rate_changes: contains following variables:
o Is_trial
o Is_conversion
o Is_churn
o Is_upgrade
o Is_downgrade
o Id
o Photographer_id
o Qualification
o Marketing_channel_id
o Kid
o Affiliate_id
o Old_rate_id
o New_rate_id
o Created
In order to calculate the # subscribers I need to do the following calculations:
(I write it down in a kind of meta language which is just a mix of SQL and the description of what I want to do, because I don´t know the correct SQL code)
Calculation 1:
SQL
Select count (foto.rate_changes.photographer_id)
From foto.rate_changes
Where foto.rate_changes.is_conversion = 1;

Calculation 2:
SQL
Select count (foto.rate_changes.photographer_id)
From foto.rate_changes
Where foto.rate_changes.is_churn= 1;

Calculation 3: result (calculation 1) – result (calculation 2)
Calculation 4: running sum of calculation 3 -->then you have the # subscribers per month
Posted
Updated 4-Apr-14 6:50am
v2
Comments
Maciej Los 4-Apr-14 12:49pm    
What have you done till now? Where are you stuck?

1 solution

Have you tried something similar to:
SQL
SELECT FT.Calculation1, FT.Calculation2, FT.Calculation1 - FT.Calculation2 AS Calculation3
FROM ((
   SELECT COUNT(foto.rate_changes.photographer_id) AS Calculation1
   FROM foto.rate_changes 
   WHERE foto.rate_changes.is_conversion = 1) AS t1
   INNER JOIN (
       SELECT COUNT(foto.rate_changes.photographer_id) AS Calculation2
       FROM foto.rate_changes
       WHERE foto.rate_changes.is_churn= 1) AS t2
   ON t1.Id = t2.Id) AS FT
 
Share this answer
 
Comments
Desmodireeic 7-Apr-14 8:19am    
Thanks, you helped me out :)
Maciej Los 7-Apr-14 9:03am    
OK, i'm glad with you.
Please, mark this answer as a solution (green button).
Cheers!
Maciej

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900