Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aggregate Function...

Status
Not open for further replies.

idog

Programmer
Mar 18, 2001
11
IL
Can I create Aggregating function by my self?
Like Sum, Avg, Max etc..

/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
Yes, but what concretly do you want to do? John Fill
1c.bmp


ivfmd@mail.md
 
Well...
I that the function will take strings and make something like OR data between them...
for example:
010010 (string)
OR
011000 (String)
=
011010

/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
no problems.
in a module:
function yourOr( x as string, y aa string) as string
....code here
yourFunction = something 'return value
end function
in a query
select yourOr(onecolumn,other) from xxx John Fill
1c.bmp


ivfmd@mail.md
 
That is not what I need.

Let say I have a table which have two fields.
1. myID - This field have duplicate values
2. myScore.

In my Query the myID field is grouped by.
I want that on every same value of myID it will multiple all the value of myScore.

For example
If I have a table like that:

myID myScore
1 3
1 4
1 2
2 5
3 5
3 2

I want that the output query will be something like that

myIDGroupedBy myMulScore
1 24
2 5
3 10
/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
Will it work?
select MyID, max(yourOr(Score, ID)) from yourtable group by MyID


function yourOr( x as int,z as int) as string
static nx as int
static nz as int
if z <> nz then
nx = 0
nz = z
endif
nx = nx or x
yourFunction = nx
end function John Fill
1c.bmp


ivfmd@mail.md
 
I don't understand...
What is &quot;YourOr(Score,ID)
What is &quot;Score&quot;, What is the ID??
/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
sorry, not MyID from our table, not ID.
But the query maybe will by more correct as:
select t.MyID, max(t.x) as x from
(select MyID, yourOr(MyScore, MyID) as x from yourtable order by MyID) as t
group by t.MyID John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top