如何按共同价值过滤
How to filter by common value
我有字段:phone_country_code 和 phone_number,例如 8(代码)和 9191501490(数字)
我需要按公共值查找记录:phone,例如 89191501490
如何决定?
仅建议:
错误 := r.Db.Where("(phone_number)+(phone_country_code)=?", phone).First(out).Error
我更愿意从phone中提取国家代码并单独查询它们(本例中的phone没有国家代码):
r.Db.Where("phone_number=? AND phone_country_code=?", phone, country_code)
但是如果你不知道它们是由什么规则组成的,你可以试试这个:
r.Db.Where("CONCAT(phone_number, phone_country_code)=?", phone)
我有字段:phone_country_code 和 phone_number,例如 8(代码)和 9191501490(数字) 我需要按公共值查找记录:phone,例如 89191501490 如何决定?
仅建议: 错误 := r.Db.Where("(phone_number)+(phone_country_code)=?", phone).First(out).Error
我更愿意从phone中提取国家代码并单独查询它们(本例中的phone没有国家代码):
r.Db.Where("phone_number=? AND phone_country_code=?", phone, country_code)
但是如果你不知道它们是由什么规则组成的,你可以试试这个:
r.Db.Where("CONCAT(phone_number, phone_country_code)=?", phone)