我通過SQL查詢將MySQL數據庫的副本發送到遠程服務器。MySQL在本地和遠程服務器上的不同查詢結果
遠程服務器:
Variable_name Value
protocol_version 10
slave_type_conversions
version 10.0.11-MariaDB
version_comment MariaDB Server
version_compile_machine x86_64
version_compile_os Linux
version_malloc_library system
本地服務器:
Variable_name Value
innodb_version 5.6.21
protocol_version 10
slave_type_conversions
version 5.6.21
version_comment MySQL Community Server (GPL)
version_compile_machine x86
version_compile_os Win32
當我運行下面的查詢,這產生兩種服務器上不同的結果。
select K, S, rn as R, G, V, T, Naam, Club, R1, R2, R3, R4, R5, R6, Totaal
from (
select K, S, G, V, T, Naam, Club, R1, R2, R3, R4, R5, R6, R1+R2+R3+R4+R5+R6 as Totaal,
@rn := case when @prev = S
then @rn + 1
else 1
end as rn,
@prev := S
from (
select K, substr(K,1,1) as S, G, V, T, L.Naam, C.naam as Club, coalesce(R1,0) R1, coalesce(R2,0) R2, coalesce(R3,0) R3, coalesce(R4,0) R4, coalesce(R5,0) R5, coalesce(R6,0) R6
from (
select clubid, naam from club) as C
join (select clubid, bondsnummer, if(mv="M", "Dhr.", "Mw.") as G, voorletters as V, tussenvoegsel as T, achternaam as Naam from lid where mv="M") as L on C.clubid=L.clubid
join (select bondsnummer, klasse as K, compdnid from deelnemer) as D on L.bondsnummer=D.bondsnummer
left join (select compdnid, rondeid, sum(score) as R1 from score where rondeid=1 group by compdnid,rondeid) as R1 on D.compdnid=R1.compdnid
left join (select compdnid, sum(score) as R2 from score where rondeid=2 group by compdnid,rondeid) as R2 on R1.compdnid=R2.compdnid
left join (select compdnid, sum(score) as R3 from score where rondeid=3 group by compdnid,rondeid) as R3 on R2.compdnid=R3.compdnid
left join (select compdnid, sum(score) as R4 from score where rondeid=4 group by compdnid,rondeid) as R4 on R3.compdnid=R4.compdnid
left join (select compdnid, sum(score) as R5 from score where rondeid=5 group by compdnid,rondeid) as R5 on R4.compdnid=R5.compdnid
left join (select compdnid, sum(score) as R6 from score where rondeid=6 group by compdnid,rondeid) as R6 on R5.compdnid=R6.compdnid
) as S, (select @prev := 0, @rn := 0) as vars
order by S, Totaal desc
) as X
where Totaal > 0
limit 0,500
結果本地服務器上,與@Rn的正確編號爲R:
而且在R列遠程服務器numering出錯:
(請注意,在本地服務器上,記錄不能被編輯,刪除,......而不是遠程。查看前幾列'wij zigen,verwijderen,...',只是顯得很遙遠。不是我需要這樣做,我只是想知道有什麼區別。)
解釋?如何解決或尋找是什麼原因造成的?
您正在使用'limit'而沒有'order by'(在外部查詢中)。結果集的排序不受子查詢中的「order by」保證,特別是在使用諸如MariaDB之類的並行數據庫時。如果需要一致的結果,請在外部查詢中輸入'order by'。 – 2015-03-13 11:06:59
我現在試過了。結果是,我在兩個服務器上獲得與在遠程服務器上運行(仍未更改)查詢時相同的錯誤模式。所以這絕對是問題,但你的建議似乎不是確切的或完整的解決方案?或者兩個服務器的查詢應該不同? – user1837293 2015-03-13 11:37:55