2012-03-26 36 views
2

我有一個SQL查詢在那裏我算select count(*)錯誤的結果,緩存還是什麼?

SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1 

我更新了一些列改變stato到「approvato」的行數,有時數()給了我正確的號碼,有時它給我的老字號

這裏是我的一塊日誌:

2012-03-23T10:42:45+01:00 DEBUG (7): Row id = 1809 
2012-03-23T10:42:45+01:00 DEBUG (7): SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1 
2012-03-23T10:42:45+01:00 DEBUG (7): Result = 140 
...change stato into 'approvato' thus count must give me 141 next time, requery the row, check changes are saved 


2012-03-23T10:44:52+01:00 DEBUG (7): Row id = 1810 
2012-03-23T10:44:52+01:00 DEBUG (7): SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1 
2012-03-23T10:44:52+01:00 DEBUG (7): Result = 140 ?!!! why not 141? 

ditta_id,agente_id,stato是指標

我使用ž最終框架1.11.11和MySQL 5.1.49-3

+0

您是不是要改變已經符合計數標準的行的值?你沒有顯示足夠的信息來真正評估這一點。 – dldnh 2012-03-26 09:48:37

+0

http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/ – Vytautas 2012-03-26 09:50:12

+0

@Vytautas - 兩個查詢都有'COUNT(*)',所以相同的行爲由NULL或NOT NULL沒有區別。 – MatBailie 2012-03-26 10:03:55

回答

3

爲您更新的行,我認爲以下是真實的......

  • ditta_id'3'
  • YEAR(data)不是一個'2012'
  • stato已經'approvato'
  • stato已經'consegnato'
  • stato新的價值有一個錯字

您能夠在這些領域之前,你改變stato後場給我們展示?

+0

我有一個非常複雜的邏輯錯誤,對不起我的錯誤 – max4ever 2012-03-26 10:29:32

相關問題