Q. Write a query to print total number of unique hackers who made at least submission each day (starting on the first day of the contest), and find the hacker_id and name of the hacker who made maximum number of submissions each day. If more than one such hacker has a maximum number of submissions, print the lowest hacker_id. The query should print this information for each day of the contest, sorted by the date.
Input Format
The following tables hold contest data:
Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker.
Submissions: The submission_date is the date of the submission, submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, and score is the score of the submission.
Solutions--
SELECT a.submission_date, a.c, h.hacker_id, h.name FROM
(
SELECT y.submission_date, COUNT(DISTINCT hacker_id) c
FROM (
SELECT z.submission_date, z.hacker_id, COUNT(DISTINCT x.submission_date) c
FROM submissions z
JOIN submissions x ON x.hacker_id = z.hacker_id AND x.submission_date <= z.submission_date AND x.submission_date >= "2016-03-01"
WHERE z.submission_date >= "2016-03-01" AND z.submission_date <= "2016-03-15"
GROUP BY z.submission_date, hacker_id
HAVING c = 1 + DATEDIFF(z.submission_date, "2016-03-01")
) y
GROUP BY submission_date
) a
JOIN (
SELECT b.submission_date, MAX(b.c) FROM (
SELECT hacker_id, submission_date, COUNT(*) c
FROM submissions
WHERE submission_date >= "2016-03-01" AND submission_date <= "2016-03-15"
GROUP BY hacker_id, submission_date
) b
GROUP BY b.submission_date
) c ON c.submission_date = a.submission_date
JOIN (
SELECT a.submission_date, MIN(a.hacker_id) h_id FROM
(
SELECT submission_date, hacker_id, COUNT(*) c FROM submissions
GROUP BY submission_date, hacker_id
) a
JOIN (
SELECT b.submission_date, MAX(b.c) max_s FROM (
SELECT hacker_id, submission_date, COUNT(*) c
FROM submissions
WHERE submission_date >= "2016-03-01" AND submission_date <= "2016-03-15"
GROUP BY hacker_id, submission_date
) b
GROUP BY b.submission_date
) e ON a.submission_date = e.submission_date AND a.c = e.max_s
GROUP BY a.submission_date
) d ON d.submission_date = a.submission_date
JOIN hackers h ON d.h_id = h.hacker_id
ORDER BY a.submission_date;
Very long ago, there lived a huge apple tree offering tasty apples to the people. A little boy became close friend to the apple tree. The boy used to play with the tree, climb the branches, sleep under the shadow, pluck apples, etc. Every day he visited the tree, and ate apples. The apple tree was so kind to the boy and enjoyed spending time with the little boy. The boy joined school and could not spend any time with the apple tree. After several months the boy came to the apple tree. The tree was so happy to see the boy and asked him to play with it. The boy said that he was not a little one to play with the trees. But he had another request to the tree. The tree asked what he wanted. The boy said that he needed toys to play, but his parents did not have sufficient money to buy toys for him. The tree replied, ‘Dear friend, I do not have any money to buy toys for you, but you can pick the apples, sell them, get money and buy the t...
Once a father and son went to the kite flying festival. The young son became very happy seeing the sky filled with colorful kites. He too asked his father to get him a kite and a thread with a roller so he can fly a kite too. So, the father went to the shop at the park where the festival was being held. He purchased kites and a roll of thread for his son. His son started to fly a kite. Soon, his kite reached high up in the sky. After a while, the son said, “Father, It seems that the thread is holding up a kite from flying higher, If we break it, It will be free and will go flying even higher. Can we break it?” So, the father cut the thread from a roller. The kite started to go a little higher. That made a son very happy. But then, slowly, the kite started to come down. And, soon it fell down on the terrace of the unknown building. The young son was surprised to see this. He had cut the kite loose of its thread so it can fly high...
not working in MS Access..any help
ReplyDelete