2016-12-06 83 views
0

您好我有數據表這樣選擇最小最大用於從數據表組數據

nickname date   is_unique 
test  01-01-2016 yes 
test  01-02-2016 yes 
test  01-03-2016 yes 
test1  01-01-2016 yes 
test1  01-02-2016 yes 
test1  01-03-2016 yes  

我嘗試組數據爲這樣

nickname startdate enddate  is_unique 
test  01-01-2016 01-03-2016  yes 
test1  01-01-2016 01-03-2016  yes 

顯示的數據,但是當我使用查詢碼分它最多隻顯示1列數據是「測試」它不顯示的「測試1」數據 這裏是我sqlquery的命令

SELECT b.nickname, min(a.date), max(a.date), a.is_unique 
FROM `table1` a 
join `table2` b 
on b.fingerid = a.acno 
where a.is_unique = 1 

回答

2

只需在您的查詢中加入GROUP BY b.nickname即可,如

SELECT b.nickname, min(a.date), max(a.date), a.is_unique 
     FROM `table1` a 
     join `table2` b 
     on b.fingerid = a.acno 
     where a.is_unique = 1 
     GROUP BY b.nickname 
+0

謝謝你的工作^^ – kanabut