select top 1 PictureID,caption  from  Pictures where Left(PictureID,6) in (
Select Left(PictureID,6) PictureID
from Pictures aa where exists (Select 1 from PictureDetails where PictureID=aa.PictureID) and AuditMark='1' and left(PictureID,2)='00' 
and Caption like '%" + Request.Params["cont"] + "%' or Contents like '%" + Request.Params["cont"] + "%' 
Group by Left(PictureID,6)) order by AuditDate Desc

解决方案 »

  1.   

    Select Top 1 PictureID,Caption from Pictures where PictureID In(Select PictureID from PictureDetails) and AuditMark='1' and left(PictureID,2)='00' and Caption like '%" + Request.Params["cont"] + "%' or Contents like '%" + Request.Params["cont"] + "%' Group by Left(PictureID,6),caption order by AuditDate Desc
      

  2.   

    按你这样写的也不对System.Data.SqlClient.SqlException: Column 'aa.Caption' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
      

  3.   

    To hjhing:
    也不对呀System.Data.SqlClient.SqlException: Column name 'Pictures.AuditDate' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
      

  4.   

    此贴子我在C#中发过,各位可以参考一下其它人的解法:http://expert.csdn.net/Expert/topic/1524/1524836.xml?temp=.3036463谢谢继续关注!
      

  5.   


    aa='Select Top 1 PictureID,Caption from Pictures where PictureID In(Select PictureID from PictureDetails) and AuditMark='1' and left(PictureID,2)='00' and Caption like '%" + Request.Params["cont"] + "%' or Contents like '%" + Request.Params["cont"] + "%' Group by Left(PictureID,6) order by AuditDate Desc'再运行你的aa,
      

  6.   

    我认为这个语句肯定没有句法问题,而语法上的确有问题,如Group By的使用等不是很清楚
      

  7.   

    是嘛,是小姐更好呀,多给点分给你啦,另外的80分也归你啦,去顶吧!该你的就拿吧------------------
    声明,本贴已由SophiaWang为我解决,现全分奉送!