Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Danny's Diner Question 10 #16

Open
A-C-Sai opened this issue Jun 11, 2024 · 0 comments
Open

Danny's Diner Question 10 #16

A-C-Sai opened this issue Jun 11, 2024 · 0 comments

Comments

@A-C-Sai
Copy link

A-C-Sai commented Jun 11, 2024

The solution given appears to have a problem. According to the solution Customer A got 1020 points and Customer B got 320.

I wasn't able to fully figure out where the problem is but I think it has to do with the join conditions. I have done the calculations by hand and through query and it resulted in Customer A with 1370 points and Customer B with 820 points.

Please correct me if I am wrong.

Below is the query that I used (MySQL):

    with date_cte as (
        select
            *,
            DATE_ADD(m.join_date, INTERVAL 6 DAY) as bonus_end
        from 
        members m
    )
    select 
        date_cte.customer_id,
        SUM(
            case
                when order_date between join_date and bonus_end then price*10*2
                when product_name = "sushi" then price*10*2
                else price*10
            end
        ) as points
    from 
        date_cte
        left join
        sales s
        on date_cte.customer_id = s.customer_id
        join
        menu m
        on m.product_id = s.product_id
    where MONTH(order_date) <= 1
    group by 1
    order by 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant