Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN TRANSACTION;
- /* Create a table called NAMES */
- CREATE TABLE IF NOT EXISTS stiri (
- titlu TEXT PRIMARY KEY,
- continut_stire TEXT NOT NULL,
- data_publicare INT DEFAULT '1556399472'
- );
- CREATE TABLE IF NOT EXISTS reporteri (
- nume_complet TEXT PRIMARY KEY NOT NULL,
- numar_telefon TEXT NOT NULL
- );
- CREATE TABLE IF NOT EXISTS stiri_reporteri (
- titlu_stire TEXT NOT NULL,
- nume_reporter TEXT NOT NULL,
- PRIMARY KEY (titlu_stire, nume_reporter),
- FOREIGN KEY (titlu_stire) REFERENCES stiri(titlu),
- FOREIGN KEY (nume_reporter) REFERENCES reporteri(nume_complet)
- );
- /* Create few records in this table */
- INSERT INTO stiri (titlu, continut_stire) VALUES
- ('stire_1', 'Starea vremii'),
- ('stire_2', 'Zodiac'),
- ('stire_3', 'Carti de citit'),
- ('stire_4', 'Sfaturi de dieta');
- INSERT INTO reporteri VALUES
- ('Andrei', '12345'),
- ('Ionut', '67890');
- INSERT INTO stiri_reporteri VALUES
- ('stire_1', 'Andrei'),
- ('stire_1', 'Ionut'),
- ('stire_2', 'Andrei'),
- ('stire_2', 'Ionut'),
- ('stire_3', 'Andrei'),
- ('stire_3', 'Ionut'),
- ('stire_4', 'Ionut');
- /*commit changes*/
- COMMIT;
- /* Display all the records from the table */
- SELECT numar_telefon FROM (stiri_reporteri JOIN
- reporteri ON
- stiri_reporteri.nume_reporter = reporteri.nume_complet) GROUP BY numar_telefon ORDER BY COUNT(numar_telefon) DESC LIMIT 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement