gpt4 book ai didi

SQL : Select a dynamic number of rows as columns

转载 作者:行者123 更新时间:2023-12-04 06:58:46 24 4
gpt4 key购买 nike

我需要选择静态列 + 动态行数作为 SQL 中的列

TABLE 1
-------
HotelID
BlockID
BlockName

TABLE 2
-------
BlockDate (unknown number of these)
NumberOfRooms

Desired Result Row
------------------
HotelID | BlockID | BlockName | 02/10/10 | 02/11/10 | 02/12/10 | ...N

其中日期列是未知数量的 BlockDate 行。

最佳答案

在客户端执行此操作。

SQL 是一种固定列语言:您不能拥有可变数量的列(即使使用 PIVOT 等)。动态 SQL 不是一个好主意。

关于SQL : Select a dynamic number of rows as columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2208197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com