錯誤碼: 1242 Subquery returns more than 1 row,1242subquery

來源:互聯網
上載者:User

錯誤碼: 1242 Subquery returns more than 1 row,1242subquery
1. 錯誤描述

1 queries executed, 0 success, 1 errors, 0 warnings查詢:SELECT t.id, DATE_FORMAT( t.statisTime, '%Y-%m-%d %H:%i:%s' ) statisTime, (SELECT `id` FROM t_truck_info WHERE id = t.plateId...錯誤碼: 1242Subquery returns more than 1 row執行耗時   : 0.009 sec傳送時間   : 0.002 sec總耗時      : 0.012 sec
2. 錯誤原因

在編寫查詢SQL語句時,其中有個欄位是從另一張表裡擷取

select t.id,(select num from t_user_info where id = stuNo) as amount from t_stu_info t left join t_user_info t0on t0.id = t.stuNo

查詢出num是多條資料,而外層查詢結果是要求num為一條資料

3. 解決辦法
select t.id,(select sum(num) from t_user_info where id = stuNo) as amount from t_stu_info t left join t_user_info t0on t0.id = t.stuNo

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.