0

下面是在 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')
4

1 回答 1

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)
于 2011-11-22T04:03:31.337 回答