SorryButImaNewbie Posted March 26, 2015 Share Posted March 26, 2015 Hello! I tried to post my question to stackoverflow, but couldn't (unknown error massage) and w3school, but i still need to be validated there to ask. I'm trying to create a query (in SQL developer), which retruns the number of emission classes of cars, grouped by country codes. I can create it for one emission class like this: SELECT DISTINCT country_code, COUNT(emission_class) EURO0 FROM DB.CUSTOMER_VEHICLE WHERE emission_class = 'E0' GROUP BY country_code; My problem that I don't know how to count for a new column for example EURO1 emission class, from the same column (emission_class). I thought that I should create views and then add them togeather, or UNION 6 different selects. Tried with where and having clauses. I always seems to run into some kind of a problem, then i realize that when I'm not sure how to start something properly, I should ask/research it first, so here I'm. Thank you for the insight! (sorry still quite fresh with SQL, thank god I haven't paid anything for university, the internet is actually way better ) Link to comment Share on other sites More sharing options...
Solution SorryButImaNewbie Posted March 26, 2015 Author Solution Share Posted March 26, 2015 I found a very good and simple solution, basicly just have to ask for the columns the right way SUM(CASE WHEN emission_class = 'E0' THEN 1 ELSE 0 END) AS EURO0 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now