1

I need an help about a sql query. I have a table as the following

error   session
error1     1 
error1     1
error2     1
error1     2
error1     2
error2     2

I have to count errors once related to session. The result should be

error   number of errors     
error1         2
error2         2

Thank you

1
  • Edit your question and provide sample data and expected results for that data. This question probably has many duplicates, but it's difficult to be sure because your question is so unclear. Commented May 25, 2017 at 7:16

2 Answers 2

4

Use aggregated function count and group by to do this.

Try this:-

Select error, count(distinct session) as number_of_errors
from
your_table_name
group by error
Sign up to request clarification or add additional context in comments.

Comments

1

You have to group by the error and count the distinct sessions, and you can do that pretty much repeating these words in a query

select  error, count(distinct session)
from    yourTable
group by error

Comments

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.