Sort by

recency

|

1878 Discussions

|

  • + 0 comments

    Here's a simple solution in MySQL: Step 1: Calculate the salary of each student Step 2: Calulate the salary of each friend Step 3: Select the students where their salary is less than that of their friend

    WITH student_salary AS
    (
        SELECT s.ID AS student_id, s.Name AS student_name, p.Salary AS student_salary
        FROM Students s
        LEFT JOIN Packages p
        ON s.ID = p.ID
    ),
    friend_salary AS
    (
        SELECT f.Friend_ID AS friend_id, f.ID AS student_id, p.Salary AS friend_salary
        FROM Friends f
        LEFT JOIN Packages p
        ON f.Friend_ID = p.ID
    )
    SELECT ss.student_name
    FROM student_salary ss
    LEFT JOIN friend_salary fs
    ON ss.student_id = fs.student_id
    WHERE ss.student_salary < fs.friend_salary
    ORDER BY fs.friend_salary;
    
  • + 0 comments

    with student_salary as ( select s.id as id, s.name as name, sum(p.salary) as salary FROM students s inner join packages p on s.id = p.id group by s.id, s.name ), bestie_salary as ( select f.id as id, f.friend_id as bst_id, sum(p.salary) as salary from friends f inner join packages p on f.friend_id = p.id group by f.id, f.friend_id ), cte as ( select s.id as id, s.name as name, s.salary as student_salary, b.bst_id as friend_id, b.salary as friend_salary from student_salary s inner join bestie_salary b on s.id = b.id ) select name from cte where friend_salary > student_salary order by friend_salary asc

  • + 0 comments

    select student_name from (select s.id student_id, s.name student_name, p.salary student_salary,
    f.friend_id friend_id, f.friend_name friend_name, f.friend_salary friend_salary from students s join packages p on p.id = s.id join (select ff.id, ff.friend_id, i.name as friend_name, pp.salary as friend_salary from friends ff join packages pp on pp.id = ff.friend_id join students i on i.id = ff.friend_id ) as f on f.id = s.id ) as mains where student_salary < friend_salary order by friend_salary

  • + 0 comments

    ****select s.name from Students s join Friends f on s.id = f.id join Packages p on s.id = p.id join Packages fp on f.friend_id = fp.id where fp.salary > p.salary order by fp.salary;

  • + 0 comments

    SELECT s.Name FROM Students s JOIN Friends f ON s.ID = f.ID JOIN Packages p1 ON s.ID = p1.ID JOIN Packages p2 ON f.Friend_ID = p2.ID WHERE p2.Salary > p1.Salary ORDER BY p2.Salary;