SELECT id ,
idUser ,
szEAN ,
szMeterAddressConcat ,
szCommodity ,
szChannelConcat ,
szEmail ,
iProcessedFlag ,
dtCreated ,
iStatus ,
iActive ,
iIgnore ,
iNumEanCount
FROM ( SELECT MAX(met.id) AS id ,
MAX(met.idUser) AS idUser ,
MAX(met.szEAN) AS szEAN ,
MAX(met.szMeterAddress) AS szMeterAddressConcat ,
MAX(met.szCommodity) AS szCommodity ,
MAX(met.szChannel) AS szChannelConcat ,
MAX(met.szEmail) AS szEmail ,
MAX(met.iProcessedFlag) AS iProcessedFlag ,
MAX(met.dtCreated) AS dtCreated ,
MAX(met.iStatus) AS iStatus ,
MAX(met.iActive) AS iActive ,
MAX(met.iIgnore) AS iIgnore ,
( SELECT COUNT(el.IDan)
FROM dbo.tblean el
WHERE el.EAN = met.szEAN
AND el.isDeleted = 0
) AS iNumEanCount ,
ROW_NUMBER() OVER ( ORDER BY MAX(met.szEAN) ASC ) AS 'RowNumber'
FROM dbo.tblcustomermeterlist AS met
WHERE met.isDeleted = '0'
GROUP BY szEAN
HAVING MAX(iNumEanCount) > 0
) AS mt
WHERE mt.RowNumber BETWEEN 1 AND 25
Я пытаюсь использовать HAVING
пункт на iNumEanCount. Кто-нибудь может дать мне знать, что я делаю неправильно в приведенном выше запросе?
Спасибо, ребята, за ваши быстрые ответы. Я внес небольшие изменения в свой запрос, и он работает нормально для меня. здесь я публикую изменения, которые я сделал.
SELECT
id,
idUser,
szEAN,
szMeterAddressConcat,
szCommodity,
szChannelConcat,
szEmail,
iProcessedFlag,
dtCreated,
iStatus,
iActive,
iIgnore,
iNumEanCount
FROM (
SELECT
MAX(met.id) as id,
MAX(met.idUser) as idUser,
MAX(met.szEAN) as szEAN,
MAX(met.szMeterAddress) as szMeterAddressConcat,
MAX(met.szCommodity) as szCommodity,
MAX(met.szChannel) as szChannelConcat,
MAX(met.szEmail) as szEmail,
MAX(met.iProcessedFlag) as iProcessedFlag,
MAX(met.dtCreated) as dtCreated,
MAX(met.iStatus) as iStatus,
MAX(met.iActive) as iActive,
MAX(met.iIgnore) as iIgnore,
ROW_NUMBER() OVER ( ORDER BY MAX(met.szEAN) ASC) AS 'RowNumber',
(SELECT count(el.IDan) FROM dbo.tblean el WHERE el.EAN = met.szEAN AND el.isDeleted
=0) as iNumEanCount
FROM
dbo.tblcustomermeterlist as met
WHERE
met.isDeleted = '0'
GROUP BY szEAN
) AS mt
WHERE mt.RowNumber BETWEEN 1 AND 25
AND iNumEanCount > 0
Других решений пока нет …