APIJSON 【where条件中有函数和比较运算】

tvmytwxo  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(82)

Description

SELECT count(1)
FROM  report_contract_assessment_terms
WHERE GREATEST(contract_start_date, '2024-03-01') <= LEAST(contract_end_date, '2024-04-01');

以上sql应该如何实现?

mm5n2pyu

mm5n2pyu1#

左侧的函数可以用 @key 映射,右侧的需要用 @raw
#627

{
    "Report_contract_assessment_terms": {
        "@column": "count(1)",
        "least_date<=": "LEAST(contract_end_date,'2024-04-01')", // 后端 DemoSQLConfig.RAW_MAP 配置下
        "@key": "least_date:GREATEST(contract_start_date,'2024-03-01')",
        "@raw": "least_date<="
    }
}
yv5phkfx

yv5phkfx2#

如果希望不配置 RAW_MAP,需要和 key{} , @column, @having 一样自动解析 SQL 函数/表达式,调用 parseSQLExpression
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2037-L2055

相关问题