0

我正在尝试将我的应用程序从 MS SQL Server 移动到 MySQL,并且我LIMIT在子查询中遇到了 MySQL 子句的问题。

SQL 服务器代码:

select F.call_Id, F.cell_Phone_Number, F.cal_DATE
From TD_Call_Log AS F
Where F.call_Id IN ( Select Top 5 S.call_Id
                      From TD_Call_Log AS S
                      where S.cell_Phone_Number = F.cell_Phone_Number)

 Order by cell_Phone_Number

我尝试过的 MySQL 代码:

select F.call_Id, F.cell_Phone_Number, F.cal_DATE
From TD_Call_Log F
Where F.call_Id IN (Select S.call_Id
                      From TD_Call_Log S
                      where S.cell_Phone_Number = F.cell_Phone_Number Limit 5)

 Order by cell_Phone_Number

我也试过:

select F.call_Id, F.cell_Phone_Number, F.cal_DATE
From TD_Call_Log F INNER JOIN (Select S.call_Id
                      From TD_Call_Log S 
 where S.cell_Phone_Number = F.cell_Phone_Number Limit 5) as t
                      ON F.call_Id = t.call_Id

 Order by cell_Phone_Number
4

1 回答 1

0

尝试用内部联接替换 In 子句中的子查询。

select F.call_Id, F.cell_Phone_Number, F.cal_DATE
From TD_Call_Log AS F 
INNER JOIN 
(
Select S.call_Id, S.cell_Phone_Number
From TD_Call_Log S
Limit 5
)
sub
where sub.cell_Phone_Number = F.cell_Phone_Number and F.call_Id = sub.call_Id
Order by cell_Phone_Number
于 2013-10-06T10:50:15.073 回答