表A与表B,表A内有字段aaa、bbb、ccc,表B内有字段ddd、eee、fff。
要求在A.aaa= '123 '和B.ddd= '456 '的两个结果中查询,条件为A.bbb=B.eee,结果列出A.aaa、A.bbb、A.ccc、B.ddd、B.eee、B.fff及重复记录的数目(就是说有几条A.bbb=B.eee的结果)这七项,结果按照重复记录的数目从大往小排列。
------解决方案--------------------
SELECT A.aaa,A.bbb,A.ccc,B.ddd,B.eee,B.fff,CNT=COUNT(1)
FROM A INNER JOIN B ON A.bbb=B.eee
WHERE A.aaa= '123 ' and B.ddd= '456 '
GROUP BY A.aaa,A.bbb,A.ccc,B.ddd,B.eee,B.fff
ORDER BY CNT DESC
------解决方案--------------------
沒看全題意
Select
A.aaa,
A.bbb,
A.ccc,
B.ddd,
B.eee,
B.fff,
Count(*) As Count
From
A
Inner Join
B
On A.bbb=B.eee
Where A.aaa= '123 ' And B.ddd= '456 '
Group By
A.aaa,
A.bbb,
A.ccc,
B.ddd,
B.eee,
B.fff
Order By
Count Desc