SQL : Select a dynamic number of rows as columns

前端 未结 4 1247
春和景丽
春和景丽 2021-01-22 23:21

I need to select static colums + a dynamic number of rows as columns in SQL

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

TABLE 2
-------
BlockDate (unknown number          


        
4条回答
  •  心在旅途
    2021-01-23 00:14

    you are missing a foreign key. I have to assume that BlockId should be PK in table 2?

    Also, assuming that this is a legacy db and changing the structure is not an option, i have to ask which platform?

    If ms sql, this could easily be achieved using a dynamic sql statement.

提交回复
热议问题