【求】各位Delphi大侠帮忙写个sql语句,在线等,急~~~~(100)

S

sunke520

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#1
降水区间大小为x,区间个数为y,(x,y都为整型),现在要统计各个对应区间降水次数,求sql语句。在线等,请大侠帮忙。。。。(为说的明白些,举个实例,假设x为10,y为3,sql语句的查询功能就是要分别统计降水量0-10,10-20,20-30各区间发生的次数)注:x,y都是未知量,求sql语句
 
W

wangdonghai

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#3
我建的表结构和数据如下:(数据库是sql server 2000)CREATE TABLE [T1] ( [Num] [int] NOT NULL , [SL] [int] NULL , CONSTRAINT [PK_T1] PRIMARY KEY CLUSTERED ( [Num] ) ON [PRIMARY] ) ON [PRIMARY]GO Num SL(降水量) 1 2 2 3 3 4 4 10 5 13 6 14 7 15 8 16 9 20 10 21...implementation{$R *.dfm}function GenSQL(const x,y:Integer):string;var sSQL,sColumn:string;
i:integer;
begin
for i:=1 to ydo
begin
sColumn:='['+inttostr((i-1)*x)+'-'+inttostr(i*x)+']';
if i>1 then
sSQL:=sSQL+',';
sSQL:=sSQL+'(select count(*) '+sColumn+' from t1 where sl between '+ inttostr((i-1)*x)+' and '+inttostr(i*x)+') a'+inttostr(i);
end;
result:='select * from '+sSQL;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//edit1.Text='10';
//edit2.Text='3';
ADOQuery1.Active:=false;
ADOQuery1.SQL.Text:=GenSQL(StrToInt(edit1.Text),StrToInt(edit2.Text));
ADOQuery1.Active:=True;
end;
 
Top Bottom