报错,sql语句中尽量不要使用*,只查询需要的字段出来

本文探讨了在SQL查询中避免使用通配符'*'的重要性,以提高查询效率。示例展示了如何精确选择所需字段,并结合子查询实现条件过滤。同时,强调了遵循最佳实践以确保数据安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误:
sql语句中尽量不要使用*,只查询需要的字段出来。


解决:
select id,tran_code,tran_name,tran_date,tran_time,tran_amount,1 as count from app_cash_trans_log order by app_cash_trans_log.id desc limit 5
select id,tran_code,tran_name,tran_date,tran_time,tran_amount,1 as count from app_cash_trans_log where app_cash_trans_log.tran_amount>=(select pla_config.cfg_value from pla_config where pla_config.cfg_name='tranMaxMmount') order by app_cash_trans_log.id desc limit 5