2014-02-28 195 views
0

我有一個查詢,顯示一些關於採購訂單的信息, 現在我有一張有獲得評分機會的表。SQL Group by Score%

這包含以下數據:

0% - Geen kans 
100% order 
0% - Klant 
20% FM > 1 jaar 
20% > 1 jaar 
40% 6 maanden 
50% 3 maanden 
60% 2 maanden 
60% FM 2 maanden 
70% 1 maand 
80& 2 weken 
90% 1 week 

現在我想組我的結果通過這個數據,在頂部的機會最高, 所以100% - > 90% - > 80% - >等。

但是;如果我使用ORDER BY score.SCORECODE ASC,它首先顯示NULL,然後是0%,然後是100%。 有沒有人有一個想法如何解決這個問題?

編輯:這是我的完整的查詢:

select distinct 
rela.name "Relatie" 
,   dealer.NAME "Dealer" 
,  (addr.STREET+' '+CAST(addr.HOUSENUMBER as varchar(30))+' '+CAST(addr.ADDITIONHOUSENUMBER AS varchar(30))+' '+addr.ZIPCODE+' '+addr.CITY+' '+coun.[NAME]) as "Relatieadres" 
,  atyp.AUTOTYPECODE "Autotype" 
,  score.SCORECODE "Verkoopstadium" 
,  type.[DESCRIPTION] "Taaktype" 
,  offe.OFFERDATE "Offertedatum" 
,  (pers.FIRSTNAME+' '+pers.LASTNAME) as "Werknemer" 
,   todo.DATECREATED as "Begindatum" 
,   todo.DUEDATE "Vervaldatum" 
,  crel.AUTOAANPASSINGCODE "type aanpassing" 
,  stat.STATE "Workflowstatus" 
,  rela.PHONE1 "Telefoonnummer" 
,  rela.PHONE2 "Relatie mobiel" 
,  (pers1.FIRSTNAME+' '+pers1.LASTNAME) as "Contactpersoon" 
,  posi.[DESCRIPTION] "Functie contactpersoon" 
,  todo.PLAINTEXT_INTERNALMEMO "Interne memo" 
from r_todo todo 
LEFT OUTER JOIN r_relation rela 
ON todo.FK_RELATION  = rela.PK_R_RELATION 
LEFT OUTER JOIN R_DEALER dela 
ON dela.FK_RELATION = rela.FK_DEALER 
LEFT OUTER JOIN r_relation dealer 
ON rela.FK_DEALER = dela.FK_RELATION 
LEFT OUTER JOIN r_todotype type 
ON todo.FK_TODOTYPE  = type.PK_R_TODOTYPE 
LEFT OUTER JOIN R_EMPLOYEE empl 
ON todo.FK_ASSIGNEDTO   = empl.PK_R_EMPLOYEE 
LEFT OUTER JOIN r_person pers 
ON empl.FK_PERSON   = pers.PK_R_PERSON 
LEFT OUTER JOIN r_address addr 
ON rela.FK_VISITINGADDRESS = addr.PK_R_ADDRESS 
LEFT OUTER JOIN r_country coun 
ON addr.FK_COUNTRY   = coun.PK_R_COUNTRY 
LEFT OUTER JOIN r_workflowstate stat 
ON todo.FK_WORKFLOWSTATE = stat.PK_R_WORKFLOWSTATE 
LEFT OUTER JOIN r_contact cont 
ON cont.FK_RELATION  = rela.PK_R_RELATION 
LEFT OUTER JOIN R_POSITION posi 
ON cont.FK_POSITION  = posi.PK_R_POSITION 
LEFT OUTER JOIN r_person pers1 
ON cont.FK_PERSON   = pers1.PK_R_PERSON 
LEFT OUTER JOIN R_offer offe 
ON offe.FK_RELATION  = rela.PK_R_RELATION 
LEFT OUTER JOIN x_r_relation xrela 
ON xrela.FK_R_RELATION  = rela.PK_R_RELATION 
LEFT OUTER JOIN c_relatieautotype atyp 
ON xrela.FK_AUTOTYPE  = atyp.PK_C_RELATIEAUTOTYPE 
LEFT OUTER JOIN c_relatieautoaanpassing crel 
ON xrela.FK_AUTOAANPASSING  = crel.PK_C_RELATIEAUTOAANPASSING 
LEFT OUTER JOIN C_RELATIESCORE score 
ON xrela.FK_SCORE  = score.PK_C_RELATIESCORE 
where todo.DUEDATE is not null 
ORDER BY score.SCORECODE ASC 
+0

那是一列? – Mihai

+0

這些是在該表中的值。我現在也添加了我的完整查詢。 – Matheno

+0

分數代碼是100%,90%等的varchar列嗎? – Mihai

回答

0
ORDER BY CASE WHEN Verkoopstadium IS NULL THEN '101%' ELSE 0 END, Verkoopstadium 
+0

消息145,級別15,狀態1,行1 如果指定了SELECT DISTINCT,那麼ORDER BY項目必須出現在選擇列表中。 – Matheno

+0

仍然沒有改變,當我刪除DISTINCT它仍然給我一個結果,從0% – Matheno