2个表合一个表sql如何写(最简单写法)
类别表(xtzd)
id |
XNAME |
XTAG |
state2 |
84 |
咖啡文化 |
文章类别 |
1 |
85 |
咖啡豆 |
文章类别 |
1 |
91 |
咖啡研磨 |
文章类别 |
1 |
92 |
xxx |
其它 |
0 |
用户表(Admin)
UserName |
bigclassid |
admin |
84, 85, 91 |
admin1 |
84, 85 |
admin2 |
84 |
结果表(xtzd, Admin)
id |
XNAME |
XTAG |
state2 |
bigclassid |
UserName |
84 |
咖啡文化 |
文章类别 |
1 |
84 |
admin2 |
或:结果表(xtzd, Admin)
id |
XNAME |
XTAG |
state2 |
bigclassid |
UserName |
84 |
咖啡文化 |
文章类别 |
1 |
84, 85, 91 |
admin |
85 |
咖啡豆 |
文章类别 |
1 |
84, 85, 91 |
admin |
91 |
咖啡研磨 |
文章类别 |
1 |
84, 85, 91 |
admin |
sql语句
select xtzd.id, xtzd.XNAME,xtzd.XTAG,xtzd.state2,Admin.bigclassid,Admin.UserName from xtzd, Admin where xtzd.XTAG='文章类别' and xtzd.state2='1' and instr(Admin.bigclassid, xtzd.id)>0 and Admin.UserName='admin' order by xtzd.XCODE
|