0
The marketing department wants to focus on the customers from North America first. Gets the ID, last name and country of all customers. Build the list by bringing up the customers living in Canada and in the USA first, and finally ordered them by ID. Tip: Use the IN expression in the ORDER BY help me please😯😐😐
8 Respuestas
+ 4
@ meri - try this code :
select customer ID, lastname, country from customer order by country in ('Canada', 'USA') desc, customer ID;
+ 2
can you share table structure please
+ 2
Here is a better solution, without using IN expression. Let me know if it helps you out -->
select id, lastname, country
from tablename
order by (case
when country='US' then 0
when country='Canada' then 1
end) desc, id asc
+ 1
I am also looking for an help to this question.
for further note: the expected result needs to have country column values as - USA and Canada values listed first, followed by the values of all other countries down in the country column.
So how a combination of nesting Order by and IN would help?
+ 1
Select Customerld, LastName, Country From customer Order by Country in ('Canada' , 'USA') DESC
something like that...
0
structur is so 59 rows, 9 columns:id ,firstname,lastname,city,state,country,email,invoicetotal,company that is all
0
thanks @Rosekamal it is true answer
0
Select Customerld, LastName, Country From customer Order by Country IN ('Canada' , 'USA') DESC