How to do left join , same table with different conditions per column

Hi i need information about how to merge both sentences

Sentence 1

select idlote from polizamovtos group by idlote having sum(cargo)-sum(abono) > 0

Sentence 2

SELECT SUM(cargo) as saldo FROM polizamovtos WHERE FECHAMOVTO='2020-01-01' GROUP BY IDLOTE

sentence 1 is the main filter

Hi, I attach more information

table polizamovtos
enter image description here

Output expected

idlote cargo
1 4000
3 4000
4 5000

Go to Source
Author: Sergio Rossetti

MySQL count results from JOIN with where clause

I’ve got two tables.

id, name, type, deleted_at

id, user_id, chat_id, deleted_at

What I’m trying to do is to select a private chat with a user ID 1, where it’s the only participant in the chat, avoiding sub-queries.

What I tried:

SELECT count( as count_users, chats.*
FROM chats
    LEFT OUTER JOIN user_chat on user_chat.chat_id =
WHERE chats.type = 'private'
    AND user_chat.user_id = 1
    AND user_chat.deleted_at IS NULL
    AND chats.deleted_at IS NULL
HAVING count_users = 1;

With all variants of group, having, etc. with no luck. Please, advice.

Go to Source
Author: Tim Mishutin