0

我需要执行以下查询:

SELECT ID FROM tbl_a WHERE (fld_merchID, 'something') IN
(SELECT MerchID, MAX(Priority) FROM tbl_b WHERE Name LIKE 'AAA.com')

如您所见,tbl_a 中没有“优先级”字段。(我需要选择优先级值较高的 MerchID)。

该查询返回空,它不应该。

我不知道该怎么做。

谢谢!

4

2 回答 2

0

试试这个 ,

 SELECT ID FROM tbl_a WHERE fld_merchID IN
(SELECT MerchID, MAX(Priority) FROM tbl_b  WHERE Name LIKE 'AAA.com')
于 2013-01-09T20:56:12.353 回答
0

如果您想要具有最高优先级的那个,那么您需要显着更改您的子查询以选择具有最高优先级的 MerchID:

SELECT ID FROM tbl_a WHERE fld_merchID IN (
  SELECT DISTINCT MerchID
  FROM tbl_b
  INNER JOIN (
    SELECT Name, MAX(Priority) as Priority
    FROM tbl_b 
    WHERE Name LIKE 'AAA.com'
    GROUP BY Name
  ) mx ON mx.Name = tbl_b.Name AND mx.Priority = tbl_b.Priority
)
于 2013-01-09T21:06:44.140 回答