The SELECT COUNT(*) FROM customer line only counts that 1 row, thus returning a value of 1,.The where country = c.country clause results in only 1 row remaining,.You know that if a given country had only 1 customer, that the following chain of events happen: This is where your counting of the rows ties back in to what the mission outlined in the quoted text I posted above. If there was only 1 customer in a country, it would return 1. If a given country had 5 customers, SELECT COUNT(*) FROM customer would return 5. So what we’re doing here is we’re counting the number of rows left after the WHERE clause we ran. Likewise if there was only 1 country - that 1 country would be singled out as its own row.
![sql server case statement sql server case statement](https://i.stack.imgur.com/HYmiS.jpg)
These 5 rows would be pinpointed by that WHERE clause. Let’s say there were 5 different customers in a particular country. This is being used of course to filter individual rows. I’ll try to explain the query from the inside out: SELECT So this gives you an idea that the equating of the sub-query to 1 must have been to identify the countries with only 1 customer.
#SQL SERVER CASE STATEMENT CODE#
So I’d love to hear the input of someone who’s actually done it.įrom looking at the solutions key, it seems like the code you just highlighted is a neat trick to identify the countries with only 1 customer.įrom reading the text in the Guided Project screen, we see the following:īecause there are a number of countries with only one customer, you should group these customers as “Other” in your analysis. I haven’t done this mission in Python, but I did do the one in R, where some approaches were different, this being one of them.