How to write such an SQL statement? It's been an afternoon.

Source: Internet
Author: User
How to write such an SQL statement? It took a whole morning! Exist table Anumid & nbsp; nameText & nbsp; GY-001 & nbsp; I am Sun GY-002 & nbsp; I am moon exist table Bnumid & nbsp; & how to write such an SQL statement? It took a whole morning!
Table
Numid nameText
GY-001 I am Sun
GY-002 I'm the Moon
Table B exists
Numid comment
GY-001 sunspots
GY-001 Sun Mian
GY-001 sun particles
GY-002 meteorite
GY-002 prehistoric civilization
The data I want to retrieve:
Numid nameText cout
GY-001 I'm Moon 3
GY-002 I'm Moon 2


------ Solution --------------------
Select a. numid, a. nameText, count (*) as cout form table A, Table B B where a. numid = B. numid group by a. numid
------ Solution --------------------

Can you try this?



SELECT A.numid,A.nameText,COUNT(A.numid) AS cout FROM A ,B WHERE A.numid = B.numid GROUP BY A.numid

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.