Home > Backend Development > PHP Tutorial > 这样一句SQL如何写?搞了一下午了

这样一句SQL如何写?搞了一下午了

WBOY
Release: 2016-06-13 11:13:56
Original
1018 people have browsed it

这样一句SQL怎么写?搞了一上午了!
存在表A
numid  nameText  
GY-001  我是太阳
GY-002  我是月亮
存在表B
numid   comment
GY-001   黑子
GY-001   日冕
GY-001   太阳粒子
GY-002   陨石
GY-002   史前文明 
我想取出的数据:
numid  nameText  cout
GY-001  我是月亮   3
GY-002  我是月亮   2


------解决方案--------------------
select a.numid, a.nameText, count(*) as cout form 表A a, 表B b where a.numid=b.numid group by a.numid
------解决方案--------------------

试一下这样看行不

<br /><br />SELECT A.numid,A.nameText,COUNT(A.numid) AS cout FROM A ,B WHERE A.numid = B.numid GROUP BY A.numid<br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template