【问题标题】:Response json not equals to sql query响应json不等于sql查询
【发布时间】:2022-10-04 22:26:43
【问题描述】:

我需要用户 id、用户名、asesor nombre、asesor telefono、asesor correo 和 tipo asesor,但 json 响应重复数据。

这是 spring 存储库中的 sql 查询。

'''

@Query( value = "SELECT U.id as userid, u.name as cliente," +
"A.nombre, A.correo, A.telefono, TA.tipo as asesoria " +
"from tc_users U, tc_usuario_asesores UA , " +
"tc_asesor A,tc_tip_asesor TA " +
"where U.id = UA.userid " +
"and UA.asesorid= A.id " +
"and A.tipo_asesor = TA.id",
 nativeQuery = true)

'''

并且 sql 工作台中的这个查询返回这个数据

query in sql workbench

但 json 响应返回此数据

Json response

并且不知道因为这已经发生,需要帮助,对不起我的英语不好。

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    由于连接,您的查询返回笛卡尔积。

    您可以添加 DISTINCT 以获取唯一行。

    @Query( value = "SELECT DISTINCT U.id as userid, u.name as cliente," +
    "A.nombre, A.correo, A.telefono, TA.tipo as asesoria " +
    "from tc_users U, tc_usuario_asesores UA , " +
    "tc_asesor A,tc_tip_asesor TA " +
    "where U.id = UA.userid " +
    "and UA.asesorid= A.id " +
    "and A.tipo_asesor = TA.id",
     nativeQuery = true)
    

    【讨论】:

      猜你喜欢
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 2013-06-23
      • 2020-05-29
      相关资源
      最近更新 更多