select date_day, term, is_first_repay, is_first_term_repay, last_month_overdue, curr_principal_amt, curr_principal_overdu_amt, curr_principal_3_overdu_amt, curr_principal_7_overdu_amt, curr_principal_15_overdu_amt, curr_principal_30_overdu_amt, reg_user_type, original_interest_type, curr_principal_2_overdu_amt, month from dm_finrisk.dwd_loan_driver_plan_day_overdue_detail_mi where month != 202304 group by month这段代码有没有问题
时间: 2023-07-21 19:25:25 浏览: 90
这段代码有问题,因为SELECT语句中的字段没有全部出现在GROUP BY语句中,GROUP BY语句中只有一个字段month。在使用GROUP BY语句时,需要保证SELECT语句中的所有字段都在GROUP BY语句中出现,或者在SELECT语句中使用聚合函数来对字段进行处理,例如SUM、COUNT等。因此,正确的写法应该是:
```
SELECT date_day, term, is_first_repay, is_first_term_repay, last_month_overdue, curr_principal_amt, curr_principal_overdu_amt, curr_principal_3_overdu_amt, curr_principal_7_overdu_amt, curr_principal_15_overdu_amt, curr_principal_30_overdu_amt, reg_user_type, original_interest_type, curr_principal_2_overdu_amt, month
FROM dm_finrisk.dwd_loan_driver_plan_day_overdue_detail_mi
WHERE month != 202304
GROUP BY date_day, term, is_first_repay, is_first_term_repay, last_month_overdue, curr_principal_amt, curr_principal_overdu_amt, curr_principal_3_overdu_amt, curr_principal_7_overdu_amt, curr_principal_15_overdu_amt, curr_principal_30_overdu_amt, reg_user_type, original_interest_type, curr_principal_2_overdu_amt, month
```
或者使用聚合函数对部分字段进行处理后再进行GROUP BY操作。
阅读全文