Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help in Order by !!

Author  Topic 

mahender
Starting Member

12 Posts

Posted - 2010-07-16 : 09:04:46


need help !!!

have a table TAB1
name | mark1 | mark2 | mark3
John | 90 | 60 | 60
Mike | 30 | 40 | 30
Andy | 30 | 20 | 70
Total| 150 | 120 | 160
---------------------------

the dificlty is that i can need the TOTAL row at the bottom as seen above and need the names in asc order.
Currently i can do only one instance either asc order or make the TOTAL at the bottom . How can i do both same query ???

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-16 : 09:16:50
ORDER BY case when name = 'Total' then 2 else 1 end, name


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mahender
Starting Member

12 Posts

Posted - 2010-07-16 : 09:46:44
hey i am sorry for this alteration in the problem.. i have used two select statements one for the selection of records
another for the total (one row) .these two are then made UNION and the result is displayd .. pls help me
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-16 : 10:03:49
select * from
(
your_first_select
UNION
your_second_select
)dt
ORDER BY case when name = 'Total' then 2 else 1 end, name



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mahender
Starting Member

12 Posts

Posted - 2010-07-16 : 10:27:49
Thanks a lot !!! i got it !!!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-16 : 10:37:16
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-16 : 11:56:41
quote:
Originally posted by mahender



need help !!!

have a table TAB1
name | mark1 | mark2 | mark3
John | 90 | 60 | 60
Mike | 30 | 40 | 30
Andy | 30 | 20 | 70
Total| 150 | 120 | 160
---------------------------

the dificlty is that i can need the TOTAL row at the bottom as seen above and need the names in asc order.
Currently i can do only one instance either asc order or make the TOTAL at the bottom . How can i do both same query ???


If you use reporting tool, do this aggregation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -