0

我有两张桌子;专辑和贷款。我在表贷款中有一个BorrowerId = RS96FM 已经丢失了它的内容,因此我想将相册中的 ShelfNumber 更新为 0。但是我不知道该怎么做,因为我首先必须找到什么的 AlbumCode BorrowerId 拥有,然后更改他们在相册中的任何 AlbumCode 的 ShelfNumber。

以下是我的 sql 语句目前的样子。

Select  AlbumCode, Performer, AlbumTitle, ShelfNumber, YearReleased, RecordCompanyCode
from    Albums 
where   ShelfNumber =(Select ShelfNumber
                    from    Albums
                    where   AlbumCode =  (Select AlbumCode
                                        from    Loans
                                        where Borrowerid ='RS96FM'
                                        **and update(Shelfnumber) = 0))
4

2 回答 2

0

我想子查询会起作用。以下查询格式适用于 sql server。

Update Albums
set ShelfNumber=0
where   AlbumCode in  (Select AlbumCode
                     from    Loans
                     where Borrowerid ='RS96FM')
于 2013-10-26T06:28:11.553 回答
0

您需要使用 UPDATE 命令。首先确保那是你的记录。首先选择:

select * from albums where shelfnumber in (
    select shelfNumber from albums where albumcode in (
    select albumcode from loans where borrowerid='RS96FM'))

如果这是您的记录,请更新:

update albums set shelfnumber=0 where shelfnumber in (
    select shelfNumber from albums where albumcode in (
    select albumcode from loans where borrowerid='RS96FM'))
于 2013-10-26T06:28:42.007 回答