Knowee
Questions
Features
Study Tools

--- assigning score for rfm metric----SELECT CustomerID, m_score,f_score,r_score, recency,frequency,monetary, CAST(ROUND((f_score+m_score)/2,0)ASINT64)AS fm_score FROM(SELECT*, CASE WHEN monetary<=m20 THEN 1 WHEN monetary<=m40 AND monetary>m20 THEN 2 WHEN monetary<=m60ANDmonetary>m40THEN3 WHENmonetary<=m80ANDmonetary>m60THEN4 WHENmonetary<=m100ANDmonetary>m80THEN5 ENDASm_score, CASEWHENfrequency<=f20THEN1 WHENfrequency<=f40ANDfrequency>f20THEN2 WHENfrequency<=f60ANDfrequency>f40THEN3 WHENfrequency<=f80ANDfrequency>f60THEN4 WHENfrequency<=f100ANDfrequency>f80THEN5 ENDASf_score,--Recencyscoringisreversed CASEWHENrecency<=r20THEN5 WHENrecency<=r40ANDrecency>r20THEN4 WHENrecency<=r60ANDrecency>r40THEN3 WHENrecency<=r80ANDrecency>r60THEN2 WHENrecency<=r100ANDrecency>r80THEN1 ENDASr_score, FROM`customer-segmentation-373712.retail.Quintiles` )

Question

--- assigning score for rfm metric----SELECT CustomerID, m_score,f_score,r_score, recency,frequency,monetary, CAST(ROUND((f_score+m_score)/2,0)ASINT64)AS fm_score FROM(SELECT*, CASE WHEN monetary<=m20 THEN 1 WHEN monetary<=m40 AND monetary>m20 THEN 2 WHEN monetary<=m60ANDmonetary>m40THEN3 WHENmonetary<=m80ANDmonetary>m60THEN4 WHENmonetary<=m100ANDmonetary>m80THEN5 ENDASm_score, CASEWHENfrequency<=f20THEN1 WHENfrequency<=f40ANDfrequency>f20THEN2 WHENfrequency<=f60ANDfrequency>f40THEN3 WHENfrequency<=f80ANDfrequency>f60THEN4 WHENfrequency<=f100ANDfrequency>f80THEN5 ENDASf_score,--Recencyscoringisreversed CASEWHENrecency<=r20THEN5 WHENrecency<=r40ANDrecency>r20THEN4 WHENrecency<=r60ANDrecency>r40THEN3 WHENrecency<=r80ANDrecency>r60THEN2 WHENrecency<=r100ANDrecency>r80THEN1 ENDASr_score, FROMcustomer-segmentation-373712.retail.Quintiles )

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a SQL query that is used to assign scores to customers based on Recency, Frequency, and Monetary (RFM) values. The RFM values are divided into quintiles and each quintile is assigned a score from 1 to 5. The scores are then used to calculate an overall FM score for each customer. Here's a step-by-step breakdown of the query:

  1. The query begins by selecting the CustomerID, m_score, f_score, r_score, recency, frequency, and monetary columns from a table named Quintiles in the retail dataset of the customer-segmentation-373712 project.

  2. The CASE statements are used to assign scores to the monetary, frequency, and recency values. If the monetary value is less than or equal to m20, a score of 1 is assigned. If it's between m20 and m40, a score of 2 is assigned, and so on. The same logic is applied to frequency and recency values.

  3. The scoring for recency is reversed, meaning that lower recency values (which indicate more recent activity) receive higher scores.

  4. Finally, the query calculates the FM score by averaging the frequency and monetary scores and rounding to the nearest whole number. The CAST function is used to convert the result to an integer.

  5. The results are then returned as a new table with each customer's ID, their RFM scores, their RFM values, and their overall FM score.

This problem has been solved

Similar Questions

Write a query to display the total_units and payable_amount of the particular meter number 'SG934826'.Note:1. Display only the total_units and payable_amount columns present in the bill table where meter_number is ‘SG934826’. Use subqueries to achieve this.2. Tables involved are bill and meter.3. Compare your executed result with the sample output given below.Sample output:

1. What is the SQL to do this result?

RFM helps a company to understand their customer’s characteristics based on their what?Choose the correct answer from below:Your score for this problem will be decided based on your FIRST SUBMISSION ONLYTransaction HistoryPersonal DetailsGeographic LocationAge, Sex and Gender

4. What is the SQL to do this result?

Write a query to display the total_units and payable_amount of the particular meter number 'SG934826'.Note:1. Display only the total_units and payable_amount columns present in the bill table where meter_number is ‘SG934826’. Use subqueries to achieve this.2. Tables involved are bill and meter.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.