> ÇýÁ¤ÀÌ wrote:
> ¾È³çÇϼ¼¿ä?
>
> ¿©·¯°³ÀÇ Ç׸ñÀÌ ÀÖÀ»¶§ ÀÌ°É group by¸¦ Çϴµ¥...
> ¸î°³¸¦ ¼±ÅÃÇؼ group byÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀÌ ÀÖ³ª¿ä?
> ¿¹¸¦ µé¸é...
> Ç׸ñÀÌ a,b,c,d,e,f(Çʵåµé)°¡ ÀÖÀ»¶§...
>
> ·±Å¸Àӽà a,b¸¦ ¼±ÅÃÇؼ(üũ¹Ú½ºÀÌ¿ë) sqlÀ» ³¯¸®¸é...
> sql.add('select a,b,sum(x) from aaa');
> sql.add('group by a,b');
> À§¿Í°°Àº ¹®ÀåÀÌ ½ÇÇàµÇ¾î¾ß ÇØ¿ä...
>
> ¼±ÅÃÇÒ ¼ö ÀÖ´Â °¹¼ö´Â ¿©·¯°³°¡ µÉ¼ö ÀÖ¾î¿ä..
> ¿¹¸¦ µé¸é c,d,f¼¼°³¸¦ ¼±ÅÃÇÒ ¼öµµ ÀÖ°í ¸»ÀÌ¿¡¿ä...
>
> ³Ê¹« °æ¿ìÀÇ ¼ö°¡ ¸¹¾Æ¼...
> ¹«½¼ ¹æ¹ýÀÌ ¾øÀ»±î¿ä?
> decisioncube¸¦ ¾²¸é µÇ´Âµ¥...¾µ¼ö ¾ø´Â »óȲÀ̶ó¼...ÂÁÂÁ...
>
> ²À Á» ¾Ë·ÁÁà¿ä...
>
> ±×·³ ¾È³çÈ÷ °è¼¼¿ä..
>
¾È³çÇϼ¼¿ä ±è¿µ´ëÀÔ´Ï´Ù
SQL¹®ÀÇ Á¶ÇÕÀº »ç½Ç ¹®ÀÚ¿ Á¶ÀÛÀ̱⠶§¹®¿¡ ¸¸µå´Â ¹æ¹ýÀº ´Ù¾çÇÕ´Ï´Ù
±×·±µ¥ Áú¹®ÇϽŠGROUP BY °¡ µé¾î°¡´Â SELECT¹®Àº °í·ÁÇÒ »çÇ×ÀÌ
ÇÑ°¡Áö ÀÖ½À´Ï´Ù
"Groups within Groups"
Áï GROUP BY µÚ¿¡ ³ª¿ÇÑ ÇʵåµéÀº ±âº»ÀûÀ¸·Î sort order
°¡ Àֱ⠶§¹®¿¡ ¿ì¼±¼øÀ§¸¦ »ý°¢ÇØ¾ß ÇÕ´Ï´Ù
¾Æ·¡ ¿¹Á¦¸¦ Çѹø µ¹·Áº¸¼¼¿ä
¸¸µå´Â ¹æ¹ýÀº ÆûÀ§¿¡ ³ª¶õÈ÷ ¹è¿ÇÑ CheckBox 5°³, Button Çϳª,
Memo Çϳª¸¦ ¿Ã·Á³õ½À´Ï´Ù
±×´ÙÀ½¿¡ ¼³Á¤ÇÒ ÇÁ·ÎÆÛƼ´Â ¼Ò½º¿¡¼ ÇϹǷΠ¼³Á¤ÇÒ ÇÊ¿ä°¡ ¾øÀÌ
¹Ù·Î ½ÇÇàÇÏ½Ã¸é µË´Ï´Ù
½ÇÇà ÈÄ °¢ CheckBox ¸¦ Ŭ¸¯ÇϽøé Memo¿¡ SELECT¹®ÀåÀÌ »ý¼ºµË´Ï´Ù
¿©±â¿¡ ¿ì¼±¼øÀ§¸¦ °í·ÁÇؼ...
¿ì¼±¼øÀ§´Â ³ªÁß¿¡ check ÇÑ°ÍÀÌ ³ô°Ô ¼³Á¤µË´Ï´Ù
±×·³ ¼ö°íÇϼ¼¿ä
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure CheckBoxAllClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CheckBoxList: TStringList;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
CheckBoxList := TStringList.Create;
// Å×À̺íÀÇ Çʵå¸í°ú ±× Çʵ带 ³ªÅ¸³»´Â CheckBoxÀÇ ¿¬°ü°ü°è¸¦ ³ªÅ¸³»¾î ÀúÀåÇÑ´Ù
CheckBoxList.AddObject('a', TObject(CheckBox1));
CheckBoxList.AddObject('b', TObject(CheckBox2));
CheckBoxList.AddObject('c', TObject(CheckBox3));
CheckBoxList.AddObject('d', TObject(CheckBox4));
CheckBoxList.AddObject('e', TObject(CheckBox5));
for i := 0 to CheckBoxList.Count-1 do
begin
// °¢ CheckBoxÀÇ Tag¿¡ ÃʱâÄ¡ 0¸¦ ³Ö´Â´Ù
TCheckBox(CheckBoxList.Objects[i]).Tag := 0;
// °¢ CheckBoxÀÇ ShowHint¸¦ È°¼ºÈ ÇÑ´Ù
TCheckBox(CheckBoxList.Objects[i]).ShowHint := True;
// °¢ CheckBoxÀÇ OnClick À̺¥Æ® ÇÒ´ç
TCheckBox(CheckBoxList.Objects[i]).OnClick := CheckBoxAllClick;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CheckBoxList.Free;
end;
procedure TForm1.CheckBoxAllClick(Sender: TObject);
var
i, j, CheckedCount: Integer;
begin
if TCheckBox(Sender).Checked then
begin
// °¡Àå ÃÖ±Ù¿¡ CheckµÈ CheckBoxÀÇ ¿ì¼±¼øÀ§¸¦ 1 ·Î ³ª¸ÓÁö´Â 1¾¿ Áõ°¡
TCheckBox(Sender).Tag := 1;
TCheckBox(Sender).Hint := IntToStr(TCheckBox(Sender).Tag) + ' ¼øÀ§';
for i := 0 to CheckBoxList.Count-1 do
if (TCheckBox(CheckBoxList.Objects[i]) <> TCheckBox(Sender)) and
(TCheckBox(CheckBoxList.Objects[i]).Tag > 0) then
begin
TCheckBox(CheckBoxList.Objects[i]).Tag := TCheckBox(CheckBoxList.Objects[i]).Tag + 1;
TCheckBox(CheckBoxList.Objects[i]).Hint := IntToStr(TCheckBox(CheckBoxList.Objects[i]).Tag) + ' ¼øÀ§';
end;
end
else // UnChecked
begin
// ¸ðµç CheckµÈ CheckBoxÀÇ ¿ì¼±¼øÀ§¸¦ 1¾¿ °¨¼Ò
for i := 0 to CheckBoxList.Count-1 do
if TCheckBox(CheckBoxList.Objects[i]).Tag > TCheckBox(Sender).Tag then
begin
TCheckBox(CheckBoxList.Objects[i]).Tag := TCheckBox(CheckBoxList.Objects[i]).Tag - 1;
TCheckBox(CheckBoxList.Objects[i]).Hint := IntToStr(TCheckBox(CheckBoxList.Objects[i]).Tag) + ' ¼øÀ§';
end;
TCheckBox(Sender).Tag := 0;
TCheckBox(Sender).Hint := '';
end;
// CheckedµÈ°ÍÀÌ ¾øÀ¸¸é SELECT¸¦ ¸¸µéÁö ¾Ê´Â´Ù
Memo1.Clear;
CheckedCount := 0;
for i := 0 to CheckBoxList.Count-1 do
if TCheckBox(CheckBoxList.Objects[i]).Tag > 0 then
Inc(CheckedCount);
if CheckedCount = 0 then
System.Exit;
Memo1.Lines.Add('SELECT');
// ¿ì¼±¼øÀ§¿¡ µû¶ó ÇʵåÀÇ À§Ä¡¸¦ °áÁ¤
for i := 1 to CheckBoxList.Count do // ¼øÀ§
for j := 0 to CheckBoxList.Count-1 do
if TCheckBox(CheckBoxList.Objects[j]).Tag = i then
Memo1.Lines.Add(CheckBoxList.Strings[j]+',');
// ¸Ç ¸¶Áö¸· comma¸¦ Á¦°ÅÇÑ´Ù
Memo1.Lines[Memo1.Lines.Count-1] :=
Copy(Memo1.Lines[Memo1.Lines.Count-1], 1, Length(Memo1.Lines[Memo1.Lines.Count-1])-1);
Memo1.Lines.Add('FROM table');
Memo1.Lines.Add('GROUP BY');
// ¿ì¼±¼øÀ§¿¡ µû¶ó ÇʵåÀÇ À§Ä¡¸¦ °áÁ¤
for i := 1 to CheckBoxList.Count do // ¼øÀ§
for j := 0 to CheckBoxList.Count-1 do
if TCheckBox(CheckBoxList.Objects[j]).Tag = i then
Memo1.Lines.Add(CheckBoxList.Strings[j]+',');
// ¸Ç ¸¶Áö¸· comma¸¦ Á¦°ÅÇÑ´Ù
Memo1.Lines[Memo1.Lines.Count-1] :=
Copy(Memo1.Lines[Memo1.Lines.Count-1], 1, Length(Memo1.Lines[Memo1.Lines.Count-1])-1);
end;
end. |
|