以下是在SQL Server 2008上正常运行的SQL。
SELECT ITEM_NO
FROM
PROPERTY_VALUES
WHERE
(PROPERTY_NAME ='Fax' AND PROPERTY_VALUE = '123-123-123')
INTERSECT
SELECT ITEM_NO
FROM
PROPERTY_VALUES
WHERE
(PROPERTY_NAME ='Email' AND PROPERTY_VALUE = 'testemail@gmail.com')
INTERSECT
SELECT ITEM_NO
FROM
PROPERTY_VALUES
WHERE
(PROPERTY_NAME ='Mobile' AND PROPERTY_VALUE = '9844808631')
答案 0 :(得分:2)
重写SQL如下,HQL应该是显而易见的:
SELECT ITEM_NO
FROM
PROPERTY_VALUES a, PROPERTY_VALUES b, PROPERTY_VALUES c
WHERE
(a.PROPERTY_NAME ='Fax' AND a.PROPERTY_VALUE = '123-123-123')
AND
(b.PROPERTY_NAME ='Email' AND b.PROPERTY_VALUE = 'testemail@gmail.com')
AND
(c.PROPERTY_NAME ='Mobile' AND c.PROPERTY_VALUE = '9844808631')
AND
(a.ITEM_NO = b.ITEM_NO AND a.ITEM_NO = c.ITEM_NO)