A more practical MySQL interview question: Game Data Recharge Query

Source: Internet
Author: User

The topic is as follows, there are two data table sub-table is, user table: Members (Qqnumber,userid); Recharge table: Payment (Payid,userid,paytime,amount); Query for the 2012 months of the most up-to-date users of the Qqnumber, required to summarize according to Qqnumber (hint: A qqnumber may have a number of top-up records, paytime to recharge the time, amount to recharge the amount), please write out the SQL statement. Create two tables First: Then create the stored procedure and insert the test data into the data table:method One:SELECT MAX (amount), T.qqnumber, T.month  From (SELECT month (a.paytime) month, B.qqnumber, SUM (a.amount) Amount  From payment A, Members B
WHERE A.userid = B.userid and year (a.paytime) = ' A ' GROUP by B.qqnumber, MONTH ' as-T group by T.month; method Two: SELECT M AX (amount), T.qqnumber, T.month From (SELECT month (p.paytime) as MONTH, SUM (p.amount) as amount, m.qqnumber as Qqnumber
From members M JOIN Payment p on m.userid = P.userid
WHERE year (p.paytime) =2012 GROUP by M.qqnumber, MONTH) as T GROUP by T.month; The result of the last query is as follows: This article is the author original, reprint please indicate the source, the wrong place welcome correct, please leave a message!

A more practical MySQL interview: Game data Recharge query

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.