A表 ID NAME 1 衬衫 2 短裤 3 毛衣 B表 ID P_ID NAME VALUE 1 1 尺寸 15 1 1 颜色 蓝色 1 2 尺寸 11 1 2 颜色 红色 1 3 尺寸 19 1 3 颜色 白色
如何查出 衬衫 且 尺寸等于15 颜色等于蓝色
最新回答
含朕的龙根
2024-11-08 09:48:03
SELECT * FROM A t WHERE NAME = '衬衫' AND EXISTS (SELECT 1 FROM B WHERE ID = t.ID and NAME = '尺寸' AND VALUE = '15') AND EXISTS (SELECT 1 FROM B WHERE ID = t.ID and NAME = '颜色' AND VALUE = '蓝色')
孤独儛埗
2024-11-08 17:31:18
SELECT * FROM A INNER JOIN B ON A.ID = B.ID INNER JOIN B.P_ID=B.P_ID WHERE A.NAME='衬衫' AND B.NAME='尺寸' AND B.VALUE='15' AND B.NAME='颜色' AND B.VALUE='红色'