使用where子句为视图选择多列查询?

时间:2013-12-16 06:06:02

标签: sql sql-server

如何将表格中的显示ID和名称输入视图。使用where子句选择display id,到目前为止我只选择display id但是现在我想从同一个表中选择名称。

老桌子是这样的。

SELECT id, 
       (SELECT displayid 
        FROM   quickpay12.q_sponsortrack AS Q_SponsorTrack_1 
        WHERE  ( f1.transferto = f1.id )) AS TransferTo, 
       (SELECT displayid 
        FROM   quickpay12.q_sponsortrack AS Q_SponsorTrack 
        WHERE  ( f1.transferby = f1.id )) AS TransferBy, 
       descid, 
       credit, 
       debit, 
       description, 
       vdate, 
       balance, 
       wallettype, 
       sno 
FROM   quickpay12.f_transactionsummary_employee AS f1 

1 个答案:

答案 0 :(得分:0)

尝试以下查询以返回所有表中的所有列:

SELECT  f1.* ,
        Q_SponsorTrack_1.* ,
        Q_SponsorTrack.*
FROM    quickpay12.f_transactionsummary_employee AS f1
        LEFT JOIN quickpay12.q_sponsortrack AS Q_SponsorTrack_1 ON f1.transferto = Q_SponsorTrack_1.id
        LEFT JOIN quickpay12.q_sponsortrack AS Q_SponsorTrack ON f1.transferby = Q_SponsorTrack.id