查询在哪里续集?

西玛·查拉姆(Simha Chalam)

where子句用于内部联接的续集。我的查询是

SELECT Cou.country_id,cou.country_name, Sta.state_id, Sta.state_name
FROM hp_country Cou
INNER JOIN hp_state Sta ON Cou.country_id = Sta.hp_country_id
WHERE (Cou.country_status=1 AND Sta.state_status=1 AND Cou.country_id=1)
AND (Sta.state_name LIKE '%ta%');

我用续集代码写的是

hp_country.findAll({
    where: {
        '$hp_state.state_status$': 1
    },
    include: [
        {model: hp_state}
    ]
})

它产生的错误是:

SELECT `hp_country`.`country_id`, `hp_country`.`country_name`, `hp_country`.`country_status`, `hp_country`.`created_date`, `hp_country`.`update_date` FROM `hp_country` AS `hp_country` WHERE `hp_state`.`state_status` = 1;
Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'hp_state.state_status' in 'where clause'
西玛·查拉姆(Simha Chalam)
hp_country.findAll({
where: {
    //main AND condition
    $and: [
        //first joint condition
        {
            $and: [
                { country_status: 1 },
                { country_id: country_id },
                Sequelize.literal("hp_states.state_status = 1"),
                Sequelize.literal("`hp_states.hp_districts`.`district_status`=1"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities`.`city_status`=1"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities.hp_locations`.`location_status`=1"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities.hp_locations.hp_sub_locations`.`sub_location_status`=1"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities`.`city_name` LIKE '%"+city+"%'")


            ]
        },

        {
            $or: [
                Sequelize.literal("`hp_states.hp_districts.hp_cities.hp_locations`.`location_name` LIKE '%"+query+"%'"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities.hp_locations.hp_sub_locations`.`sub_location_name` LIKE '%"+query+"%'"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities.hp_locations.hp_sub_locations.hp_property`.`property_name` LIKE '%"+query+"%'"),
                Sequelize.literal("`hp_states.hp_districts.hp_cities.hp_locations.hp_sub_locations.hp_property.hp_builder`.`builders_name` LIKE '%"+query+"%'")

            ]
        }
    ]
},
attributes: ['country_id', 'country_name'],
required:true,
include: [
    {
        model: hp_state,
        attributes: ['state_id', 'state_name'],
        required:true,

        include: [
            {
                model: hp_district,
                attributes: ['district_id', 'district_name'],
                required:true,
                include: [
                    {
                        model: hp_city,
                        attributes: ['city_id', 'city_name'],
                        required:true,

                        include: [
                            {
                                model: hp_location,
                                attributes: ['location_id', 'location_name'],
                                required:true,
                                include: [
                                    {
                                        model: hp_sub_location,
                                        attributes: ['sub_location_id', 'sub_location_name'],
                                        required:true,
                                        include: [
                                            {
                                                model: hp_property,
                                                attributes: ['property_id', 'property_name'],
                                                required: true,
                                                include: [
                                                    {
                                                        model:hp_builders,
                                                        attributes: ['builders_id', 'builders_name'],
                                                        required: true

                                                    }
                                                    ]
                                            }
                                            ]


                                    }]

                            }]

                    }]
            }
        ]
    }
]

})

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在哪里续集功能

来自分类Dev

MySQL查询在哪里-> IF

来自分类Dev

在哪里存储私钥以进行持续集成(CI)部署?

来自分类Dev

LINQ在哪里查询JToken

来自分类Dev

python mysqldb查询在哪里

来自分类Dev

或在哪里查询模型

来自分类Dev

在哪里保存查询?

来自分类Dev

续集如果未提供查询,请删除“哪里”?

来自分类Dev

SQL查询在哪里和不同

来自分类Dev

Kibana查询语言的参考文档在哪里?

来自分类Dev

LINQ查询中的if语句在哪里

来自分类Dev

教义查询的建立条件在哪里

来自分类Dev

主义查询在哪里-多对多

来自分类Dev

在哪里用Time.now查询

来自分类Dev

MySQL联接查询在哪里和喜欢

来自分类Dev

Yii框架在哪里执行查询

来自分类Dev

下面的查询在哪里做什么?

来自分类Dev

Ruby格式的DateTimeParameter在哪里查询

来自分类Dev

PostgreSQL repmgr在哪里发送查询

来自分类Dev

Rails 5在哪里或活动记录查询

来自分类Dev

该查询逻辑的错误在哪里?

来自分类Dev

在哪里对存储库进行多个查询

来自分类Dev

Mysql子查询不在哪里

来自分类Dev

MySQL:查询和COUNT BY的子句在哪里?

来自分类Dev

ActiveRecord在哪里查询孙子代的属性

来自分类Dev

sql查询中的条件在哪里

来自分类Dev

Laravel雄辩的查询在哪里喜欢关系?

来自分类Dev

RedBean php计数查询在哪里

来自分类Dev

我的查询中的错误在哪里