CREATE VIEW必须是批处理中的唯一语句

 snail 发布于 2022-12-07 20:44

我正试着看一看.到目前为止,我写了这个:

with ExpAndCheapMedicine(MostMoney, MinMoney) as
(
    select max(unitprice), min(unitprice)
    from Medicine
)
,
findmostexpensive(nameOfExpensive) as
(
    select tradename
    from Medicine, ExpAndCheapMedicine
    where UnitPrice = MostMoney
)
,
findCheapest(nameOfCheapest) as
(
    select tradename
    from Medicine, ExpAndCheapMedicine
    where UnitPrice = MinMoney
)

CREATE VIEW showing
as
select tradename, unitprice, GenericFlag
from Medicine;

不幸的是,我在包含的行上收到错误 CREATE VIEW showing

"CREATE VIEW必须是批处理中唯一的声明"

我怎样才能解决这个问题?!

1 个回答
  • 正如错误所述,CREATE VIEW语句需要是查询批处理中的唯一语句.

    在此方案中,您有两个选项,具体取决于您要实现的功能:

      CREATE VIEW查询放在开头

      CREATE VIEW showing
      as
      select tradename, unitprice, GenericFlag
      from Medicine;
      
      with ExpAndCheapMedicine(MostMoney, MinMoney) as
      (
          select max(unitprice), min(unitprice)
          from Medicine
      )
      ,
      findmostexpensive(nameOfExpensive) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
          where UnitPrice = MostMoney
      )
      ,
      findCheapest(nameOfCheapest) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
              where UnitPrice = MinMoney
          )
      

      使用GO热膨胀系数之后和之前CREATE VIEW查询

      - 选项#2

      with ExpAndCheapMedicine(MostMoney, MinMoney) as
      (
          select max(unitprice), min(unitprice)
          from Medicine
      )
      ,
      findmostexpensive(nameOfExpensive) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
          where UnitPrice = MostMoney
      )
      ,
      findCheapest(nameOfCheapest) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
          where UnitPrice = MinMoney
      )
      
      GO    
      
      CREATE VIEW showing
      as
      select tradename, unitprice, GenericFlag
      from Medicine;
      

    2022-12-11 02:12 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有