This is the following, I have two tables, the esc_usuarios
table that contains information for registered users and esc_usuarios_slog
, which contains the records of the lows, in which they are performed through a button that changes the usu_situacao
column % to ativo
.
What I want is to create a function where, if there is no drop in the last 30 days, the user is set to inativo
.
esc_usuarios:
________________________________
|usu_codigo|usu_nome|usu_situacao|
|----------|--------|------------|
| 32 | Diogo | ativo |
|________________________________|
esc_usuarios_slog: usu_slog_codigo
is the user id
________________________________________________________
|usu_slog|usu_slog_codigo|usu_slog_data|usu_slog_situacao|
|--------|---------------|-------------|-----------------|
| 4 | 32 | 2018-10-08 | ativo |
|________________________________________________________|
What I have for now is the query that looks for casualties in the last 30 days:
SELECT * FROM esc_usuarios_slog
WHERE usu_slog_data
between (CURDATE() - INTERVAL 1 MONTH ) and CURDATE()
ORDER BY usu_slog_data DESC
And also the one that makes UPDATE
to inativo
:
UPDATE esc_usuarios SET usu_situacao = 'inativo'";
These two queries are handled inside if and else if.
So I need to give this update to users who do not have a drop in the esc_usuarios_slog
table.