2012-09-24 114 views
-1

這是我的表:Zend框架:選擇重複的行

mat_id| yes| no | type 
    1 | 1 | 0 | 3 
    1 | 1 | 0 | 3 
    2 | 1 | 1 | 3 
    3 | 1 | 0 | 3 

我的選擇查詢:

$q = $db->select()->from('tableName', 'mat_id')->where('type = ?', 3)->group('yes')->having('COUNT(yes) > 1'); 

但爲什麼選擇mat_id = 1而已,應該採取mat_id =1,3

+0

我續得到you.Do你的意思是你要選擇另一列..? – Gautam3164

+0

對不起,但這個問題是不可理解的。你需要明確你希望我們提供的幫助。你目前的成果是什麼?期望的結果是什麼? – Lobo

回答

0

試試這個,

$db->select()->->distinct()->from('tableName', 'mat_id')->where('type = ?', 3)->group('yes')->having('COUNT(yes) > 1'); 
+0

再次只選擇'mat_id = 1' – Defense

+0

你只是說只顯示mat_id = 1,3。爲此,你的條件應該是where('type =?AND no =?',array(3,0))。應該是$ db-> select() - > - > distinct() - > from('tableName','mat_id') - > where('type =?AND no =?',array(3,0)) - > group(array('yes','mat_id')) - > having('COUNT(yes)> 1'); – Tarun

+0

我不知道爲什麼,但再次只選擇mat_id = 1 – Defense