mardi 1 août 2017

How to select values from two select queries and do a difference between them in SQLite?

What I'm trying to do in the below query is do UNION ALL between two Select queries and then do a difference between them. I have an IF condition if the difference is greater than or equal to 2, I do select values from these two Select Subqueries from which I'm making UNION:

SELECT IF((INTER1.STUDENT_FRIEND_GRADE - INTER2.STUDENT_GRADE) >= 2)
    THEN SELECT STUDENT_GRADE, STUDENT_NAME, STUDENT_FRIEND_GRADE, STUDENT_NAME
    FROM ((SELECT H.grade AS STUDENT_GRADE, H.name AS STUDENT_NAME FROM Highschooler H 
    INNER JOIN Likes L 
    ON H.ID = L.ID1) INTER1
    UNION ALL
    (SELECT H.grade AS STUDENT_FRIEND_GRADE, H.name AS STUDENT_NAME FROM Highschooler H
    INNER JOIN Likes L 
    ON H.ID = L.ID2) INTER2)
    ) INTER3

Aucun commentaire:

Enregistrer un commentaire