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
- city street adrestype
- sincan plevne st. replacement1
- sincan plevne st. main
- sincan plevne st. replacement2
- sincan bosna st. replacement2
- sincan bosna st. replacement1
- sincan bosna st. main
but want adrestype goes periodically below
- city street adrestype
- sincan plevne st. main
- sincan plevne st. replacement1
- sincan plevne st. replacement2
- sincan bosna st. main
- sincan bosna st. replacement1
- 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
Post a Comment