我的查询工作正常;但是,我需要将另一个数据集加入到我的查询中,并且我希望 count(f.*)
会破裂。
这是我开始的查询:
SELECT
MIN(received_date) AS FirstVisit
, patient_id AS PatientID
INTO #LookupTable
FROM F_ACCESSION_DAILY
SELECT
f.doctor AS Doctor
, COUNT(f.*) AS CountNewPatients
, MONTH(firstvisit) AS Month
, YEAR(firstvisit) AS Year
FROM F_ACCESSION_DAILY f
INNER JOIN #LookupTable l ON f.received_date = l.FirstVisit
AND f.patient_id = l.PatientID
GROUP BY f.doctor
, MONTH(firstvisit)
, YEAR(firstvisit)
DROP TABLE #LookupTable
我想在另一个表上加入上述查询。
问题是*我的count(f.*)
保持不变还是会因为我添加了新数据集而改变?*
**我如何确保 count(f.*)
会保持不变吗?
非常感谢您的指导。
最佳答案
will my
count(f.*)
stay the same or will it change because I've added a new dataset?*
COUNT(*)
计算行数。如果加入另一个表,行数增加,COUNT(*)
的结果会增加。
How do I make sure that the
count(f.*)
will remain the same?
使用 COUNT (DISTINCT f.Id)
。
关于sql - 执行附加连接时,Count (*) 是否会扭曲所需的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12902852/