现在的位置: 首页 > 综合 > 正文

学习 SQL 语句 – Select(8): 分组条件

2011年08月28日 ⁄ 综合 ⁄ 共 425字 ⁄ 字号 评论关闭
代码文件:

//分组条件可以是 Where
procedure TForm1.Button1Click(Sender: TObject);
begin
  with ADODataSet1 do begin
    Close;
    CommandText := 'SELECT Continent, AVG(Area) AS 平均面积 ' +
                   'FROM country WHERE Continent="South America" GROUP BY Continent';
    Open;
  end;
end;

//也可以是 Having
procedure TForm1.Button2Click(Sender: TObject);
begin
  with ADODataSet1 do begin
    Close;
    CommandText := 'SELECT Continent, AVG(Area) AS 平均面积 ' +
                   'FROM country GROUP BY Continent HAVING Continent"South America"';
    Open;
  end;
end;

抱歉!评论已关闭.