蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年8月25日 8:28

sql查询结果集

我想根据查询结果集为条件再查询该怎么写?例:
  先在A表中查询并获得一段日期集合"2005-01-01"~"2005-03-01",再以此查询结果为条件查询A表中所有在此期间的记录.

因为每一个日期如"2005-02-18"都有好多条记录,需要筛选为每一个日期只出现一次,

怎么写?可把我的思维搞乱了~~~~~~~~~~~~~~~

select  DISTINCT * form jilu between 2005-01-01 and 2005-03-01

select DISTINCT * form A where jilu between 2005-01-01 and 2005-03-01

谢谢,这个我知道,问题是我还需要根据这个结果再查询,怎么办?

我相我有必要让解答者知道我的目的:


源表:

日期                   类别          名称            售出         
2005-01-01         香烟         红塔山         1200
2005-01-01         香烟     七匹狼      2300
2005-01-01         酒        高粱         200
2005-01-04         酒       高粱       200
2005-01-04        香烟     红塔山     1200
2005-02-08         酒       剑南春       2300
2005-02-08         酒       高粱         200

想输出格式:

日期           售出合计         
2005-01-01          3700
2005-01-04          1400
2005-02-08          2500

理不清!5~~~~55555~~~~~~~

看来我还是贴出相关代码好:

(本文件即为:pjgl.asp)

<html>
<head>
<title></title>
</head>
<%
  set my_conn= Server.CreateObject("ADODB.Connection")
  my_conn.ConnectionTimeout=20
  my_conn.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=XXX;password=XXXXX;Initial Catalog=XXXXX;Data Source=XXXXX"
  my_conn.open
  if my_conn.State=1 then
    set rst = Server.CreateObject("ADODB.Recordset")
    rst.ActiveConnection=my_conn
  end if      
%>
<body>
  <form name=postinfo1 method=post action="pjgl.asp">
查询时间从<input tabindex=1 maxlength=40 size="20" name=first>至<input tabindex=1 maxlength=40 size="20" name=last>  <input type="submit" value="查询"><input type="reset" value="重填">
  </form>

  <form name=postinfo2 method=post action="XXX.asp">
    <table><tr><td>
      <table><tr class=header>
                <td align=center width="40%">日期</td>
                <td align=center width="40%">金额合计</td>
             </tr>

       <%
          first=trim(request.Form("first"))
          last=trim(request.Form("last"))

          strSQL = "SELECT DISTINCT SalesDate FROM Day_Income_detail where SalesDate between '"&first&"' and '"&last&"'"
          rst.CursorType=3
          rst.open strSQL

                        do While not rst.eof
                                       ddd=rst("SalesDate")
%>
             <tr>
                <td align=center bgcolor="#f8f8f8"><%=rst("SalesDate")%></td>

<%                                     rst.movenext
                                    if rst.eof=true then
                                       Exit Do
                                    end if
                        loop
                                       rst.close
%>


                <td align=center bgcolor="#f8f8f8">
<%
    strSQL = "SELECT Sales_money FROM Day_Income_detail where ticket_price='6' and channel='三车道'"
          rst.CursorType=3
          rst.open strSQL

                        do While not rst.eof
                                       rst.movenext
                                    if rst.eof=true then
                                       Exit Do
                                    end if
                                   response.Write "sun"&rst(0)
                        loop

                                   rst.close
%>
         </td></tr>
      </table></table>
  </form>
<%
  my_conn.Close
  set my_conn=nothing  
%>
</body>
</html>




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com