1

Topic: It is necessary to write request

It is necessary to write request which result answers a question:
How many users on each of products in April received  and deleted a product, received  and left a product. (On condition that  was later )?

2

Re: It is necessary to write request

SELECT COUNT (user_sales.user_id)
FROM user_sales
LEFT JOIN user_events ON user_sales.user_id = user_events.user_id, user_sales.product = user_events.product
where user_sales.date = ' 2016-04'
and user_sales.payment_status = ' refund'
and user_events.event = ' uninstall'
and user_sales.date <user_events.date
group by user_sales.product

Prompt, what in the decision not so?

3

Re: It is necessary to write request

The help.
Date contains three values: year-month-number.
To April there correspond dates from ' 2016-04-01 ' to ' 2016-04-30 ' inclusively.

4

Re: It is necessary to write request

It is necessary so:

between ' 2017-10-01 ' and ' 2017-10-31 11:59:59 PM'

Statuses with  are better for storing in digits: 0 1 2 3 4
The user / a product / sales - 3 separate tables (sales = the Normal form (Google))

5

Re: It is necessary to write request

And  ' product ' = STRING? In the same place ID = INT  to be

6

Re: It is necessary to write request

tip78;
Product not ID, and text value

7

Re: It is necessary to write request

Yuliia wrote:

tip78;
Product not ID, and text value

And should be ID

8

Re: It is necessary to write request

tip78;
Why? In this basis the full title of a product is underlined. Instead of its slip number or ID.
It is real working basis.

9

Re: It is necessary to write request

What tasks this basis, if not solves a secret?
So that, is sick on  the careless student similar. The table of users is, to it refer user_id. Quite standard approach. And the table of products is not present, that to it to refer. Or at each purchase the product is strictly individual, so to say, handwork?

10

Re: It is necessary to write request

Yuliia wrote:

tip78;
Why? In this basis the full title of a product is underlined. Instead of its slip number or ID.
It is real working basis.

Because on the full title of a product do not do  and searches (if only it not of the form of search request)

11

Re: It is necessary to write request

How it generally in a basket to store and in broad gulls - everywhere the full titles to stick??