字段一对多sql语句写法的详细介绍
字段一对多sql语句写法的详细介绍
表A
A1 | A2 | A3 | A4 |
01 | 02 | 03 | 04 |
03 | 04 | 01 | 02 |
表B
B1 | B2 |
01 | 张三 |
02 | 李四 |
03 | 王五 |
04 | 赵六 |
显示结果
A1 | A2 | A3 | A4 |
张三 | 李四 | 王五 | 赵六 |
王五 | 赵六 | 张三 | 李四 |
效果图:
sql语句如下
SELECT (SELECT B2 FROM B WHERE B1=A1) AS A1, (SELECT B2 FROM B WHERE B1=A2) AS A2, (SELECT B2 FROM B WHERE B1=A3) AS A3, (SELECT B2 FROM B WHERE B1=A4) AS A4 FROM A
这样就ok了