赞
踩
test1表应用test2表的字段,test1表把test2表的id通过逗号分隔存到test1表中的一个字段
字段分隔sql:
- SELECT
- a.id as id,
- a.name as name,
- substring_index(
- substring_index(
- a.products,
- ',',
- (b.help_topic_id + 1)
- ),
- ',' ,- (1)
- ) AS shareholder
- FROM
- (
- school.test a
- JOIN mysql.help_topic b ON (
- (
- b.help_topic_id < (
- (
- length(a.products) - length(
- REPLACE (a.products, ',', '')
- )
- ) + 1
- )
- )
- )
- )
字段分隔查询出来的sql是多条的,多表联合查询怎么关联:
创建一个视图,把上面查询语句放到视图中,使用视图名称多表查询关联,例如上面sql视图名称为 view1,和test2表关联查询
- SELECT
- *
- FROM
- view1 a,
- test2 b
- WHERE
- a.shareholder = b.id;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。