Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: sr
- * Date: 17/04/17
- * Time: 16:01
- */
- /*
- Given the two tables below, write a SQL query that uses a join statement to list all users from the user table, their average correct answers, as well as the time of their most recently taken test. All user entries should appear, even if they have not taken a test.
- */
- $sql = "
- SELECT user.user_id, CONCAT(user.first_name, ' ', user.last_name) as full_name, test_result.test_id, AVG(test_result.correct) as avg_correct, MAX(test_result.time_taken) as recent_time
- FROM user
- LEFT JOIN test_result ON test_result.user_id = user.user_id
- GROUP BY user.user_id
- ORDER BY recent_time DESC;
- -- ORDER BY `avg_correct` DESC, recent_time DESC;
- ";
Add Comment
Please, Sign In to add comment