1. 程式人生 > >mysql查詢user_id重複資料

mysql查詢user_id重複資料

在專案中遇到一個問題,在呼叫findByUserIdAndStartTime()這個jpa裡面的方法,報錯: javax.persistence.NonUniqueResultException: result returns more than one elements.

最後在資料庫裡面用了下面一條sql語句查詢user_id>1的資料,看是否有資料錯誤:

SELECT user_id,start_time FROM ovuola_test.physiological_estimate_data where user_id in (select user_id from ovuola_test.physiological_estimate_data group by user_id having count(1) >= 2);