Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to output data from two SQL tables?

I need to find clients whose personal account balance is more than 100. Output client_id,balance, find clients who have more than 3 sim cards. Output name, number of sim cards, find customers whose birthday is next month. Output name, birth_date. I do not understand how these tasks can be done, I have tried many options. I am very grateful for the help

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here is one way:

select 
    c.*
from
    clients c
    left join accounts a on a.client_id = c.client_id
    left join 
        (select account_id, count(*) cnt from sim_cards group by account_id) s 
            on s.account_id = a.account_id
where
    s.cnt > 3
    and a.balance > 100
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading