Sql complicated order clause -


i have table contains state,city,street etc. , each street there 3 adres. first main, , others replacement1,replacement2.

i ordering result city , street. result below

  1. city street adrestype
  2. sincan plevne st. replacement1
  3. sincan plevne st. main
  4. sincan plevne st. replacement2
  5. sincan bosna st. replacement2
  6. sincan bosna st. replacement1
  7. sincan bosna st. main

but want adrestype goes periodically below

  1. city street adrestype
    1. sincan plevne st. main
    2. sincan plevne st. replacement1
    3. sincan plevne st. replacement2
    4. sincan bosna st. main
    5. sincan bosna st. replacement1
    6. sincan bosna st. replacement2

is possible.

assuming 3 columns city, street , adrestype, , sample data 1 row city = sincan, street = plevne st., adrestype = main, can shown below:

select city, street, adrestype yourtable order city, street desc, adrestype 

this first sort in ascending alphabetical order city, in descending order street "plevne st." shown before "bosna st.", , sorts adrestype in ascending order "main" @ top, followed "replacement1" , "replacement2" in order.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -