0

我正在处理一个 SQL 查询,请这个查询显示这个错误

Msg 116, Level 16, State 1, Line 2
当子查询没有用 EXISTS 引入时,只能在选择列表中指定一个表达式。

这是查询

select 
   *,
   (select top 1 * 
    from tbl_Renewal 
    where supid = b.S_id 
      and Payed = 1 
    order by 
      renewalid desc) as result 
from 
    tbl_SuperAdmin as b 
inner join 
    tbl_Renewal as c on b.S_id = c.supid

请检查并给我解决方案

此实际任务的任何其他解决方案

请找到下面的任务简介

表 1 'tbl_SuperAdmin'已归档

数据样例

s_id name age gtc.......
1     abc  23 .........
2     cda  42 ..........

另一个表2有'tbl_Renewal'

renewalid  renname date supid   Payed etc......
1          first   -     1        1    ........
2          first   -     2        1    ........
3          second -      1        0     ........
4          second -      1        1     ........
5          third-        1        1     ........

谢谢 pradeep

4

2 回答 2

1

您不能将 * 放在单列值中,

查询应该是这样的

select 
       *,
       (select top 1 COLUMNNAME from tbl_Renewal where supid=b.S_id and Payed=1) as result 
from tbl_SuperAdmin as b inner join tbl_Renewal as c on b.S_id=c.supid
于 2013-03-22T07:10:19.307 回答
0

将其缩短到sql以下

 select top 1 a.*,b.*

 from tbl_Renewal a inner join tbl_SuperAdmin as b

 on b.S_id=c.supid where a.Payed=1 order by b.renewalid desc
于 2013-04-24T09:12:15.630 回答