下面的代码出现了一个奇怪的错误。No column was specified for column 2 of 'no1'.
据我所知,它应该可以工作。我只是想收集有关客户在收据上不止一次存在的客户的详细信息。
SELECT
CM.ClientID,
CPN.Birthdate,
CM.ClientPassword
FROM
dbo.ClientMaster AS CM
JOIN dbo.ClientPerson AS CPN ON (CM.ClientID = CPN.ClientID)
JOIN dbo.ClientProduct AS CP ON (CPN.ClientID = CP.ClientID)
WHERE
CM.ClientID IN (
SELECT
no1.ClientID
FROM
(
SELECT
CM.ClientID,
COUNT(*)
FROM
dbo.ClientMaster AS CM
JOIN dbo.ClientPerson AS CPN ON (CM.ClientID = CPN.ClientID)
JOIN dbo.ClientProduct AS CP ON (CPN.ClientID = CP.ClientID)
WHERE
CP.PolicyNo IN (SELECT PolicyNo FROM Receipts)
AND CM.ClientID IS NOT NULL
AND Birthdate IS NOT NULL
AND ClientPassword IS NOT NULL
GROUP BY
CM.ClientID
HAVING
COUNT(*)>1
) AS no1
)
解决方案
啊没有意识到你不需要Count(*)
. Select
多谢你们!这就是我最终的结果。
SELECT DISTINCT
CM.ClientID,
CPN.Birthdate,
CM.ClientPassword
FROM
dbo.ClientMaster AS CM
JOIN dbo.ClientPerson AS CPN ON (CM.ClientID = CPN.ClientID)
JOIN dbo.ClientProduct AS CP ON (CPN.ClientID = CP.ClientID)
WHERE
CM.ClientID IN (
SELECT
ClientID
FROM
Receipts
GROUP BY
ClientID
HAVING
COUNT(*)>1
)
AND CM.ClientID IS NOT NULL
AND Birthdate IS NOT NULL
AND ClientPassword IS NOT NULL