Ask a question about the MySQL list

Source: Internet
Author: User
A1

A2

A3


Three tables now I'm writing the words
Select A1.*,sum (A2.money) as money from A1 left joins A2 on A1.id=a2.id left joins A3 on a2.no = A3.no GROUP by a1.id;
The result is


Due to other factors must be connected to the A3 table, resulting in Money 35, I want Money to 25, how should I write?


Reply to discussion (solution)

A3.no not unique, resulting in a2.no=a3.no when A2 (11 1 10.00) appears two times
So you need to constrain the A3.

A3.no not unique, resulting in a2.no=a3.no when A2 (11 1 10.00) appears two times
So you need to constrain the A3.


Yes, I thought there is any way to solve, it seems that can not be linked to the list looked.
If written
Select A1.name,
(select SUM (count) from A3 where no in (select No from a2 where id = a1.id)) as Count,
SUM (A2.money) as money
From A1 left join A2 on a1.id=a2.id Group by A1.id;
The result is

But I want money, minus count, what should I write?
25-400
20-200
  • 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.