心剑 发表于 2005-9-21 15:09:24

[江湖告急+在线等候] 在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 )&gt;=0   --KAISI RIQI <BR>AND DATEDIFF(DAY,A.RQ, '2005.7.31' )&gt;=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) '&lt;=12:00'<BR>FROM #AAA<BR>WHERE HOUR&lt;=12<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P><BR>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '&gt;12-14'<BR>FROM #AAA<BR>WHERE HOUR &gt; 12<BR>AND HOUR&lt;=14<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P><BR>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '14-18'<BR>FROM #AAA<BR>WHERE HOUR &gt;14<BR>AND HOUR&lt;=18<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>
<P>SELECT VIPTYPE, ZHIYE, SEX, SUM(XFCS) '&gt;18'<BR>FROM #AAA<BR>WHERE HOUR &gt;18<BR>GROUP BYVIPTYPE, ZHIYE, SEX</P>

<P><BR> </P>

阿辉 发表于 2005-9-22 07:59:21

<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 )&gt;=0   --KAISI RIQI <BR>AND DATEDIFF(DAY,A.RQ, '2005.7.31' )&gt;=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>

阿辉 发表于 2005-9-22 08:00:52

<P>在临时表里多加一列week就搞定了。</P>
<P>原来的SQL不是你写的吧,如果是你写的,应该很容易就搞定的呀</P>
<P>呵呵</P>
页: [1]
查看完整版本: [江湖告急+在线等候] 在SYBASE查询中加入星期函数

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com