SQL Server group by status query problem -
SQL Server group by status query problem -
table temp
id status 1 completed 2 approved 3 paid 4 cancel 5 approved 6 paid i want display above recored per bellow table without using union.because client requirement, please provide help this.
table temp
id status 1 completed 2 approved 5 approved 3 paid 6 paid 4 cancel
almost identical dan's answer, sql server (or standards sql database system):
select id, status temp order case status when 'completed' 1 when 'approved' 2 when 'paid' 3 when 'cancel' 4 end other concerns -
1) title of question appears misleading, since it's not grouping @ all, and,
2) think have misconception union - there's no guarantee of order in results homecoming union or union all - in union case, there's likely sort operation help server eliminate duplicates, sort performed exclusively server , shouldn't rely on such sort beingness necessary. union all, imagine if first query big query, requiring lot of i/o, , sec query trivial (say, of info required in memory). obvious optimization server homecoming results sec query whilst it's still performing i/o first.
sql-server
Comments
Post a Comment