首页 > 解决方案 > 如何按共同值过滤

问题描述

我有字段:phone_country_code 和 phone_number,例如 8(代码)和 9191501490(号码) 我需要按常用值查找记录:电话,例如 89191501490 如何确定?

只建议: err := r.Db.Where("(phone_number)+(phone_country_code)=?", phone).First(out).Error

标签: postgresqlgogo-gorm

解决方案


我更愿意从电话中提取国家代码并单独查询(本例中的电话没有国家代码): r.Db.Where("phone_number=? AND phone_country_code=?", phone, country_code)

但是如果你不知道它们是由什么规则组成的,你可以试试这个: r.Db.Where("CONCAT(phone_number, phone_country_code)=?", phone)


推荐阅读