简体   繁体   中英

sql count function with subquery

here is my query

select narr,vocno,count(*) 
from KontenLedger 
WHERE VOCDT>'2018-07-01' 
group by narr,vocno 
having count(*)<'3'

actually if i wright as i given above ,the result which calculates two fields ('narr' and 'vocno') if i remove the field ('narr') answer is correct. i need to view the field 'narr' also without counting

Without knowing your database, nor having some limited sample date, nor expected output?

SELECT
 vocno, 
 COUNT(*) AS total,
 MAX(narr) AS max_narr
FROM KontenLedger 
WHERE vocdt > '2018-07-01' 
GROUP BY vocno 
HAVING COUNT(*) < 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM