[江湖告急+在线等候] 在SYBASE查询中加入星期函数
<P>各们大大,一个月里分别统计周一至周日的人数。如果在下查询中加入呀?</P><P>IF (object_id('#AAA')) IS NOT NULL DROP TABLE #AAA</P>
<P>select D.VIPTYPE, C.ZHIYE, ISNULL(C.SEX,2) SEX ,<BR>DATEPART(hh,E.JYSJ) HOUR,<BR>30*round(DATEPART(mi,JYSJ)/30,0) BAN ,<BR>COUNT(*) XFCS<BR>INTO #AAA<BR> from VIPXFJLA,VIPXX C, VIPDEF D, SKTXSJL E <BR> WHERE A.SKTNO=E.SKTNO <BR>AND A.JLBH=E.JLBH <BR>and DATEDIFF(DAY, '2005.7.1', A.RQ )>=0 --KAISI RIQI <BR>AND DATEDIFF(DAY,A.RQ, '2005.7.31' )>=0--JIE SHU RIQI <BR>AND C.VIPTYPE =D.VIPTYPE<BR>AND A.VIPID = C.VIPID<BR>GROUP BY D.VIPTYPE, C.ZHIYE, C.SEX , <BR>DATEPART(hh,E.JYSJ),<BR>30*round(DATEPART(mi,E.JYSJ)/30,0)</P>
<P><BR>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '<=12:00'<BR>FROM #AAA<BR>WHERE HOUR<=12<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P><BR>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '>12-14'<BR>FROM #AAA<BR>WHERE HOUR > 12<BR>AND HOUR<=14<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P><BR>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '14-18'<BR>FROM #AAA<BR>WHERE HOUR >14<BR>AND HOUR<=18<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '>18'<BR>FROM #AAA<BR>WHERE HOUR >18<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P><BR> </P> <P>select D.VIPTYPE, C.ZHIYE, ISNULL(C.SEX,2) SEX ,<STRONG><FONT color=#0000ff>DATEPART(dw,A.RQ) WEEK,</FONT></STRONG>DATEPART(hh,E.JYSJ) HOUR,<BR>30*round(DATEPART(mi,JYSJ)/30,0) BAN ,<BR>COUNT(*) XFCS<BR>INTO #AAA<BR>from VIPXFJLA,VIPXX C, VIPDEF D, SKTXSJL E <BR>WHERE A.SKTNO=E.SKTNO <BR>AND A.JLBH=E.JLBH <BR>and DATEDIFF(DAY, '2005.7.1', A.RQ )>=0 --KAISI RIQI <BR>AND DATEDIFF(DAY,A.RQ, '2005.7.31' )>=0--JIE SHU RIQI <BR>AND C.VIPTYPE =D.VIPTYPE<BR>AND A.VIPID = C.VIPID<BR>GROUP BY D.VIPTYPE, C.ZHIYE, C.SEX , <STRONG><FONT color=#0000ff>DATEPART(dw,A.RQ),</FONT></STRONG>DATEPART(hh,E.JYSJ),30*round(DATEPART(mi,E.JYSJ)/30,0)</P> <P>在临时表里多加一列week就搞定了。</P>
<P>原来的SQL不是你写的吧,如果是你写的,应该很容易就搞定的呀</P>
<P>呵呵</P>
页:
[1]