Order by in MySQL -
i have table zipcode this
code state region distance 25696 1 5 150 25692 1 4 60 25691 2 3 50 25690 2 2 233 25688 3 4 450 25686 3 5 560 25685 4 7 50 12069 4 8 30 12068 4 5 60 12067 6 3 80 12066 7 1 90
now want sort data if state 4 selected first order state 4 regions distance rest, regardless of region, sorted distance.
so result should this
code state region distance 12068 4 5 60 25685 4 7 50 12069 4 8 30 25691 2 3 50 25692 1 4 60 12067 6 3 80 12066 7 1 90 25696 1 5 150 25690 2 2 233 25690 2 2 233 25686 3 5 560
first state 4 regions in ascending order rest date sorted distance regardless of region , states.
i m trying following query
select region,br.state, case when state = 4 -1 else state end stateorder, zipcode order stateorder,region, distance asc;
this query gives state 4 regions first in sorted order rest data sorted state , region , need fix.
please suggest.
select * zipcode order field(state,4) desc , case when state=4 region end , distance;
Comments
Post a Comment