I encountered a data format such as 100000-130000-130400-130426 in the development. The AreaEncoding field in the a table is the id splicing of the area table b. I want to query the province information of the b table through the association of the province id of 130,000 in the a table.
Figure 1 Table a
Figure 2 b table
The query sql is applied to the function substring of mysql, directly on the demo:
sleclet * from a left join b on substring(a.AreaEncoding,8,6) = b.ID;
In the actual development, you can add the where condition. I don’t want to thank the editor. The substring function is mainly used. If you have a better way, you can leave a message. The premise business logic must be sql query