更新时间:2022-03-08 22:48:03
您拥有的是一个属性表.如果您想一次测试多个属性,则需要将表自身连接起来:
What you have is a properties table. When you want to test multiple properties at once you need to join the table to itself:
SELECT c0.car_id
FROM table_cars AS c0
JOIN table_cars AS c1 ON c1.car_id=c0.car_id
JOIN table_cars AS c2 ON c2.car_id=c1.car_id
WHERE c0.name='MAKE' AND c0.value='FORD'
AND c1.name='COLOR' AND c1.value='SILVER'
AND c2.name='TOPSPEED' AND c2.value='200KM/H'
在属性表中是否存在代理id
是令人怀疑的.它似乎什么也没做.每个属性都不是其自己的实体.除非其他元素需要id
,否则我将放弃它,并将car_id, name
用作主键(复合主键).
Having the surrogate id
present in a properties table is questionable. It doesn't seem to be doing anything; each property isn't an entity of its own. Unless the id
is required by some other element, I'd get rid of it and make car_id, name
the primary key (a composite primary key).