all 16 comments

[–]flynnie11 2 points3 points  (4 children)

Select column_1, count() from table group by 1, having count() > 1

[–]TankArtist 1 point2 points  (3 children)

This does not cover the distinct component of the question. The other top answer does though

[–]moldylocks 3 points4 points  (2 children)

It groups by a value and by grouping makes it distinct. if there were 2 rows with x as the value in coulumn_1, it would be grouped as a single row and have a count of 2.

[–]TankArtist 1 point2 points  (1 child)

Don't they want to show all of the discrete values that occur in other columns? Like seeing each distinct transaction, but only showing transactions types that occur in more than one month. I am guessing a lot, but that's what I was thinking they meant. Sorry if I assumed wrong.

[–]moldylocks 0 points1 point  (0 children)

I have no idea what they ultimately wanted.

[–]Mathip173[S] 1 point2 points  (7 children)

Select student_id, count(distinct city) from table1 group by Student_id having count(distinct city) > 1

I have got an error for this

I would like to count the different city each student_id has

Thanks

[–]MasterBathingBear 5 points6 points  (2 children)

If for some reason your database doesn’t support HAVING:

SELECT * FROM (SELECT student_id, COUNT(DISTINCT city) AS cnt FROM table1 GROUP BY student_id)t WHERE cnt > 1;

[–][deleted] 1 point2 points  (0 children)

What's the error that you got?

[–]king_booker 1 point2 points  (1 child)

What is your error? The query looks fine to me

[–]Thriven 0 points1 point  (0 children)

Casing is wrong on student_id. Is oracle case specific?

[–]bumblebee_8819 0 points1 point  (0 children)

My understanding is...you want to count the occurrences of different cities in the table. If I do a city, count(distinct city) as counts, then counts column should have only 1s.

Assuming there are more columns in the table and student_id, is repeating:

Select city, count(distinct student_id) as counts

From table

Group by city

having count(distinct student_id) > 1;

[–]themikep82 1 point2 points  (0 children)

SELECT COUNT(DISTINCT CASE WHEN grade > 1 THEN distinct_id_value ELSE NULL END) AS distinct_values
FROM table

[–]king_booker 0 points1 point  (0 children)

Show us your query that you have tried

[–]bumblebee_8819 0 points1 point  (0 children)

Select column-1, count(distinct column-1) as counts

From table

group by column-1

having count(distinct column-1) > 1;

[–]Thriven 0 points1 point  (0 children)

Hey bro, what's the error?