2013年12月15日星期日

hql statement question " Sort "

hql statement follows This is a dynamic table , and now want to query a dynamic state equal 4 , and the order sorted by the specified field (trenOrder), then sort of rules are trenOrder either equal to 0, equal to 0 to put the final surface .
from Trends t where t.checkStatus = 4 ORDER BY t.trenOrder
------ Solution - ------------------------------------------
trenOrder either equal to 0 equal to 0 put last.

did not say clear. Is not ascending , but put the last 0 ? So you can use union. Remove the previous query 0 , followed by a special is 0 .
!
from t where trenOrder = 0 order by trenOrder union from t where trenOrder = 0;
------ Solution --------------------------------------------
can actually points two-step inquiry, as follows:
The first step is to query : dynamic state is equal to 4 , and the order sorted by the specified field (trenOrder), then sort of rules are trenOrder either equal to 0 ;
second query is : trenOrder equal to 0.
The result is a collection of two queries and can be.
------ For reference only -------------------------------------- -

sorry I did not make it clear that is the case. other parameters , I do not say. 2,3,4,0,0,0,9,3,2
After sorting should be 2,2,3,3,4,9,0,0,0 like this, we can do ?
------ For reference only -------------------------------------- -

sorry I did not make it clear that is the case. other parameters , I do not say. 2,3,4,0,0,0,9,3,2   
After sorting should be 2,2,3,3,4,9,0,0,0 like this, we can do ?  

Well, as I said before it can do .

没有评论:

发表评论