0

I'm coming to you because I currently have a problem with a SQL query.

Let me explain :

I have two tables, the first say tableA, record all the different terminals that connected to my application:

enter image description here

The COIDTE field corresponds to the identifier of the terminal (unique).

Then I have a second table say tableB which records all connections to the application and stores the identifier of the connected terminal (COIDTE) and the jailbreak status of the terminal (if 0 non-jailbreak terminal).

enter image description here

I am asked to return the number of trusted terminal, knowing that a terminal is said to trust if there has been at least 5 connections or jailbreak status is 0.

I can not do that with one request ... I tried several things but I can not combine everything .. thx for help :)

i tried :

Select count(a.COIDTE),
From TableA a, TableB b
Where a.COIDTE= b.COIDTE
HAVING ( Select count( distinct COIDTE ) from tableA where CTJDTE ='0'
4
  • left join the two tables and select the counts, group by and use having Commented Feb 9, 2018 at 9:57
  • Most people here want formatted text, not images. Commented Feb 9, 2018 at 9:59
  • What have you tried? Show us your current query attempt. Commented Feb 9, 2018 at 9:59
  • i updated my answer but my query doesn't work.. @dbajtr can you explain left join and having ? Commented Feb 9, 2018 at 10:06

1 Answer 1

1

Try this:

SELECT COUNT(*) FROM TableB GROUP BY COIDTE HAVING COUNT(*)>4 OR SUM(CTJBTE)=0;
Sign up to request clarification or add additional context in comments.

4 Comments

This doesn't work.. expected result is a count of correct device
I just adjusted the query. Try again!
Thx, this works, however i think there is a problem in the query i have 1751 different device, if i just run : SELECT count() FROM TableB GROUP BY COIDTE HAVING COUNT()>4) this return me : 66. so there is only 66 Device with at least 5 No Jailbreak connexion ? But with your query i get 1240 ?
Thx for you answer, i tried a mix with your differents answers and this finaly works =D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.