php mysql sort result by value of field using position of substring -
i have field name "codehead" values
"53/066/10" "54/066/05" "56/066/09" "52/069/15" "53/069/02" "67/069/02" "00/020/80" "00/020/98"
i want results in following order
"00/020/80" "00/020/98" "53/066/05" "53/066/10" "54/066/09" "52/069/15" "53/069/02" "67/069/02"
i have tried query
$data= mysql_query("select codehead,sign, sum(amt) amt pm month='$pmmonth' , rc='r' group substr(codehead,4,3) asc,substr(codehead,7,2) asc, sign ")
but not complete result.
this expression:
substr(codehead,7,2)
is returning forward slash , digit. looks wanted start @ position 8.
but won't satisfy order shown, fifth row has 09
, , come before 10
on preceding row. desired result shown makes result ordered on left(codehead,2)
group codehead, `sign` order substr(codehead,4,3) asc , left(codehead,2) asc , substr(codehead,8,2) asc
note: in future release of mysql, non-standard mysql extension of group by
imply order by
may removed.
i'm suspicious of group by
on substrings. that's valid sql that, question how want handle codehead
values match on substrings, different in other place... given you're returning codehead
in select
list.
the normative pattern group by
expressions in select
list.
Comments
Post a Comment