• Thinkphp6 中连接 SQL Server 并使用子查询报错:当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式


    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 内部封装的。

    分情破爱始乱弃,流落天涯思别离。 如花似玉负情意,影如白昼暗自迷。 随风浮沉千叶落,行色匆匆鬓已稀。
  • 相关阅读:
    抓包工具之Charles
    docker之服务搭建
    Linux之查看开放端口
    Centos7下的开机自启动
    phpredis和predis
    Redis迁移工具之Redis-shake
    服务器间文件实时双向同步(rsync+inotify)
    Linux之轨迹记录(script)
    Redis集群之常用操作
    Redis集群搭建-多服务器
  • 原文地址:https://www.cnblogs.com/cshaptx4869/p/15466443.html
Copyright © 2020-2023  润新知