0

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

3
  • 6
    Please Edit your question and add some sample data and the expected output based on that data. Formatted text please, no screen shots. edit your question - do not post code or additional information in comments. Commented Jul 28, 2018 at 10:36
  • 2
    Unrelated tip: you are comparing the numeric count value against a string '3'. If you remove the quotes, SQL won't have to implicitly convert it. Commented Jul 28, 2018 at 11:12
  • 1
    In addition to the aforementioned by a_horse_with_no_name and Richardissimo, it's worthwhile to clarify the database used. Commented Jul 28, 2018 at 11:29

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

@nashvamuhammed Really? Okay that's good. Thought it was going to need some database specific function. Like f.e. STRING_AGG for MS Sql Server. But I was probably just overthinking it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.