0
It’s the following guys, I have two tables, the table esc_usuarios
which contains information from registered users and esc_usuarios_slog
, that contains the records of the casualties, in which they are performed through a button that changes the column usu_situacao
for ativo
.
What I want is to create a function where, if there are no casualties 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 so far 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 who does the UPDATE
for inativo
:
UPDATE esc_usuarios SET usu_situacao = 'inativo'";
These two queries are dealt with within if and if Else.
Hence I need to give this update to users who do not have a low table esc_usuarios_slog
.
I’ve done the treatment with if and Else, the problem is it update the correct users.
– Luann Sousa
I need to know how to insert a Where there where will only be updated to inactive, users who have no low, in my query and yours, it will update everyone to inactive
– Luann Sousa
I get it. Do this, if you return any results in the low query, foreach the low, and in each loop you run the update command, passing the user code. I’ll edit my answer so you can see
– Tácio Brito