Solving a SQL solution

Source: Internet
Author: User
Solve a SQL
Suppose there are three tables below.
Ta
TA_ID (primary key) Ta_name Ta_cont Ta_typeid

Tb
TB_ID (primary key) Tb_taid Tb_cont

Tc
TC_ID (primary key) Tc_tatypeid Tc_type

Where Tb_taid corresponds to ta_id,tc_tatypeid corresponding to Ta_typeid, now a SQL out Ta_name,ta_cont,count (tb_taid), tc_type how to write

That's what I wrote, but no, count (tb_taid) as com goes out the count of all the IDs, not the count of each ta_id, how do I write

Select Ta_name,ta_cont,count (tb_taid) as Com,tc_type from TA left join TB on Ta_id=tb_taid LEFT join TC on TA_TYPEID=TC_TA typeID ORDER BY ta_id Desc;

------Solution--------------------
You don't have to assign a group key, and you don't get the right results.
------Solution--------------------

Select Ta_name,ta_cont,count (tb_taid) as Com,tc_type from TA left join TB on Ta_id=tb_taid LEFT join TC on TA_TYPEID=TC_TA typeID GROUP by Ta_cont ORDER by ta_id Desc;

This kind of naming makes people look dizzy. In short, use GROUP by =_= ...
  • 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.