1
有問題與MySQL變量和統計
的代碼如下:MySQL用戶定義的變量和COUNT
SELECT @var := 2, @var := @var+2, count(birey_dil.birey_id) as count, @var := @var+count(birey_dil.birey_id), @var+1 from birey_dil
下面是結果集:
+-----------+----------------+-------+----------------------------------------+--------+ | @var := 2 | @var := @var+2 | count | @var := @var+count(birey_dil.birey_id) | @var+1 | +-----------+----------------+-------+----------------------------------------+--------+ | 2 | 4 | 8 | 12 | 5 | +-----------+----------------+-------+----------------------------------------+--------+
我設置無功2
然後2 + 2 = 4
然後我計算行數,結果爲8
@var:= @ VAR +計數(birey_dil.birey_id)
返回4 + 8 12 但 @變種+ 1是5
爲什麼MySQL的作用就像是什麼?
@ var + 1現在應該是13,有沒有辦法解決這個問題?
這很可怕。你想達到什麼目的? – Mat 2011-04-15 16:34:04