问题描述
ACCESS中这样一张表IDUSERIDA_NUMB_NUM12130.91022117.956356306489206我想把同一USERID下A_NUM相加求和再加同一USERID下B_NUM最高数字就是:(30.9+17.9)+56=104.8最后把104.8输入到页面<%=rs("num")%>求SQL语句求SQL语句求SQL语句求SQL语句求SQL语句求SQL语句求SQL语句求SQL语句exec="selectsum(num)from(selectsum(A_NUM)asnumfromsp_dd_tempwhereDD_USERID="&Session("userid")&"unionallselectmax(B_NUM)asnumfromsp_dd_tempwhereDD_USERID="&Session("userid")&")"setrs=server.createobject("adodb.recordset")rs.openexec,conn%><%=rs("num")%>这样写是不是错了。请高手指点!
解决方案
解决方案二:
IDUSERIDA_NUMB_NUM12130.91022117.956356306489206我想把同一USERID下A_NUM相加求和再加同一USERID下B_NUM最高数字就是selectDD_USERID,sum(A_NUM)asaSum,sum(A_NUM)+max(B_NUM)asbSumfromsp_dd_tempgroupbyDD_USERID不知道你是不是想要这样的结果
解决方案三:
SELECTa.UserID,a.SumA+b.MaxBASTotalFROM(SELECTuseridASUserID,SUM(A_Num)ASSumAFROMTableAccessGROUPBYuserid)aINNERJOIN(SELECTuseridASUserID,MAX(B_Num)ASMaxBFROMTableAccessGROUPBYuserid)bONa.UserID=b.UserID
组成两张表不就行了
解决方案四:
引用2楼starfd的回复:
SELECTa.UserID,a.SumA+b.MaxBASTotalFROM(SELECTuseridASUserID,SUM(A_Num)ASSumAFROMTableAccessGROUPBYuserid)aINNERJOIN(SELECTuseridASUserID,MAX(B_Num)ASMaxBFROMTableAccessGROUPBYuserid)bONa.UserID=b.UserID组成两张表不就行了
傻逼了,干嘛要分两次……
解决方案五:
谢谢各位给我的灵感,搞定了selectsum(A_NUM)+max(B_NUMasnumfromsp_dd_tempwhereDD_USERID="&Session("userid")