读书人

语句报错 怎么解决 多谢

发布时间: 2012-10-12 10:17:04 作者: rapoo

语句报错 请教高手如何解决 谢谢。
select count(*) from systemMessage where (userid,avid) in (
select top 10 userid,avid from ( select distinct userid,avid from Interactive where interResult is not null and avid is not null and convert(varchar(10),interdate,120)=convert(varchar(10),getdate(),120) ) i order by newid() )



[解决办法]
select count(*) from systemMessage where (userid,avid) in (
select top 10 userid,avid from ( select distinct userid,avid from Interactive where interResult is not null and avid is not null and convert(varchar(10),interdate,120)=convert(varchar(10),getdate(),120) ) i order by newid() )

sqlserver没这种语法,换exists吧
[解决办法]

SQL code
SELECT  COUNT(*) FROM    systemMessage a WHERE   EXISTS ( SELECT 1                  FROM   ( SELECT TOP 10                                     userid ,                                     avid                           FROM      ( SELECT DISTINCT                                                 userid ,                                                 avid                                       FROM      Interactive                                       WHERE     interResult IS NOT NULL                                                 AND avid IS NOT NULL                                                 AND CONVERT(VARCHAR(10), interdate, 120) = CONVERT(VARCHAR(10), GETDATE(), 120)                                     ) i                           ORDER BY  NEWID()                         ) b                  WHERE  a.userid = b.userid                         AND a.avid = b.avid ) 

读书人网 >SQL Server

热点推荐