Thinkphp6 中连接 SQL Server 并使用子查询报错
语句
打印 SQL 语句
MySQL 下
SELECT `NickName`,`Gender`,`Mobile`,`RealName`,`Birthday` FROM `SiteCustomerSupplement` `s`
INNER JOIN `WxUser` `u` ON `u`.`OpenId`=`s`.`OpenId`
WHERE `s`.`OpenId` IN (SELECT DISTINCT `OpenId` FROM `WxPackagesOrder` WHERE `OrderStatus` >= 40 AND `RegionId` = 72) AND `Birthday` BETWEEN '2021-10-26' AND '2021-11-02'
SQL Server 下
SELECT T1.* FROM (SELECT thinkphp.*, ROW_NUMBER() OVER ( ORDER BY rand()) AS ROW_NUMBER FROM (SELECT [NickName],[Gender],[Mobile],[RealName],[Birthday] FROM [SiteCustomerSupplement] [s]
INNER JOIN [WxUser] [u] ON [u].[OpenId]=[s].[OpenId]
WHERE [s].[OpenId] IN (SELECT T1.* FROM (SELECT thinkphp.*, ROW_NUMBER() OVER ( ORDER BY rand()) AS ROW_NUMBER FROM (SELECT DISTINCT [OpenId] FROM [WxPackagesOrder] WHERE [OrderStatus] >= 40 AND [RegionId] = 72) AS thinkphp) AS T1) AND [Birthday] BETWEEN '2021-10-26' AND '2021-11-02') AS thinkphp) AS T1
很明显比 MySQL 的语句长了很多,主要是这一段
SELECT thinkphp.*, ROW_NUMBER() OVER ( ORDER BY rand()) AS ROW_NUMBER FROM
那么问题来了怎么解决?换成原生的语句就好了,不要用 tp 内部封装的。