A separate city sql query

Asked

Viewed 45 times

0

My Brand Sales Chart: City for which the sale was made, date and time of sale.
I would like to pull all sales sorted by date and time, but with a specific separate city.

For example:
For sale 12 - Brasilia - 2017-05-29 10:00:00
Sale 20 - Brasilia - 2017-05-29 11:00:00
For sale 31 - Brasilia - 2017-05-29 12:00:00

And then all other sales from all other cities sorted by date.

  • "And then all other sales sorted by date." from the same city or all other cities?

2 answers

3


Simple, just use the Where to the desired city and order by to sort by date if you want to select data from only one city.

Select * from SuaTabela where colunaCidade = "Brasilia" order by colunaData

to select all data and sort first by a specific city:

Select * from SuaTabela order by (colunaCidade = "Brasilia") desc,colunaData

-2

You will need two queries, one with city='Brasilia' and the other with city<>'Brasilia'. And join the two with UNION.

  • I agree with the use of "Union", but the answer could have included the full code to solve the problem

  • 1

    The solution from @Leo Longhi is much better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.