Schema relazionale
- UTENTI(IDutente, Cognome, Nome, DataNascita, Username, Password, DataIscrizione, Stato, …)
- AMICIZIE(utenteID1, utenteID2, Data/Ora, Stato)
- PARAGRAFI(IDparagrafo, Titolo, Testo, Data/Ora, …, utenteID)
- MIPIACEP(paragrafoID, utenteID, Data/Ora, …)
- COMMENTI(IDcommento, Titolo, Testo, Data/Ora, …, paragrafoID, utenteID)
- MIPIACEC(commentoID, utenteID, Data/Ora, …)
Query
- Gli utenti, in ordine alfabetico
123SELECT *FROM UTENTIORDER BY Cognome, Nome - I paragrafi di un certo utente
123SELECT PARAGRAFI.*FROM PARAGRAFIWHERE utenteID = '$codice' - Le coppie di amici (richiedente, ricevente) e da quando
1234SELECT U1.*, U2.*, DATAFROM (UTENTI AS U1 INNER JOIN AMICIZIE ON U1.IDutente = AMICIZIE.utenteID1)INNER JOIN UTENTI AS U2 ON AMICIZIE.utenteID2 = U2.IDutenteORDER BY U1.Cognome, U1.Nome, U2.Cognome, U2.Nome - Tutte le coppie di amici in ordine di Username
12345678SELECT U1.username AS User1, U2.username AS User2FROM (UTENTI AS U1 INNER JOIN AMICIZIE ON U1.IDutente = AMICIZIE.utenteID1)INNER JOIN UTENTI AS U2 ON AMICIZIE.utenteID2 = U2.IDutenteUNIONSELECT U2.username, U1.usernameFROM (UTENTI AS U1 INNER JOIN AMICIZIE ON U1.IDutente = AMICIZIE.utenteID1)INNER JOIN UTENTI AS U2 ON AMICIZIE.utenteID2 = U2.IDutenteORDER BY User1, User2 - Tutti gli amici di un certo utente in ordine alfabetico
12345678SELECT UTENTI . * , DATAFROM UTENTI INNER JOIN AMICIZIE ON UTENTI.IDutente = AMICIZIE.utenteID1WHERE AMICIZIE.utenteID2 = XUNIONSELECT UTENTI . * , DATAFROM UTENTI INNER JOIN AMICIZIE ON UTENTI.IDutente = AMICIZIE.utenteID2WHERE AMICIZIE.utenteID1 = XORDER BY Cognome, Nome, DATA - Gli utenti che hanno apprezzato un certo paragrafo
1234SELECT UTENTI.IDutente, UTENTI.Cognome, UTENTI.NomeFROM UTENTI INNER JOIN MIPIACEP ON UTENTI.IDutente = MIPIACEP.utenteIDWHERE MIPIACEP.paragrafoID = [Codice paragrafo?]ORDER BY Cognome, Nome - I commenti, con gli autori, di un certo paragrafo
12345SELECT COMMENTI.DATA, COMMENTI.Titolo, COMMENTI.Testo,UTENTI.IDutente, UTENTI.Cognome, UTENTI.NomeFROM COMMENTI INNER JOIN UTENTI ON COMMENTI.utenteID = UTENTI.IDutenteWHERE COMMENTI.paragrafoID = [Codice paragrafo?]ORDER BY COMMENTI.DATA DESC - Quante richieste di amicizia effettuate da un certo utente (tramite il codice)
123SELECT Count(*) AS NumeroFROM AMICIZIEWHERE utenteID1 = [Codice?] - Quante richieste di amicizia effettuate da ogni utente (il codice)
1234SELECT utenteID1 AS 'Codice utente', Count(*) AS NumeroFROM AMICIZIEGROUP BY utenteID1ORDER BY utenteID1 - Quante richieste di amicizia effettuate da ogni utente e in questo momento attive
12345SELECT utenteID1 AS 'Codice utente', Count(*) AS NumeroFROM AMICIZIEWHERE Stato = 1GROUP BY utenteID1ORDER BY utenteID1 - Quanti commenti e quanti apprezzamenti per ogni paragrafo
123456789SELECT PARAGRAFI.*,(SELECT Count(*)FROM COMMENTIWHERE COMMENTI.paragrafoID = PARAGRAFI.IDparagrafo) AS 'Numero commenti' ,(SELECT Count(*)FROM MIPIACEPWHERE MIPIACEP.paragrafoID = PARAGRAFI.IDparagrafo) AS 'Numero mi piace'FROM PARAGRAFIORDER BY PARAGRAFI.DATA - I codici dei 10 paragrafi più commentati
1234SELECT TOP 10 paragrafoID AS 'Codice paragrafo', Count(*) AS NumeroFROM COMMENTIGROUP BY paragrafoIDORDER BY Numero DESC - I codici dei 10 utenti più commentati
1234SELECT TOP 10 PARAGRAFI.utenteID AS [Codice utente], Count(*) AS NumeroFROM PARAGRAFI INNER JOIN COMMENTI ON PARAGRAFI.IDparagrafo = COMMENTI.paragrafoIDGROUP BY utenteIDORDER BY Count(*) DESC - I 10 utenti più commentati
12345SELECT TOP 10 IDutente AS 'Codice utente', Cognome, Nome, Count(*) AS NumeroFROM (UTENTI INNER JOIN PARAGRAFI ON UTENTI.IDutente = PARAGRAFI.utenteID)INNER JOIN COMMENTI ON PARAGRAFI.IDparagrafo = COMMENTI.paragrafoIDGROUP BY IDutente, Cognome, NomeORDER BY Numero DESC - I 10 utenti più apprezzati per i paragrafi
12345SELECT TOP 10 IDutente AS [Codice utente], Cognome, Nome, Count(*) AS NumeroFROM (UTENTI INNER JOIN PARAGRAFI ON UTENTI.IDutente = PARAGRAFI.utenteID)INNER JOIN MIPIACEP ON PARAGRAFI.IDparagrafo = MIPIACEP.paragrafoIDGROUP BY IDutente, Cognome, NomeORDER BY Count(*) DESC