dbTalk Databases Forums  

filtering resultset on summary field

comp.databases.filemaker comp.databases.filemaker


Discuss filtering resultset on summary field in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Twan Kennis
 
Posts: n/a

Default filtering resultset on summary field - 12-12-2006 , 11:20 AM






Have some slight problem filtering my data based on a summary field.

Situation:
2 databases: [customer], [order]
each record in database [order] has a customerid , which is the foreign
key to database [customer]
database [order] has also a counted summary field "number_of_orders".

I have a report, which groups by all orders based on a customer.
In the group-by header (print-layout), the number of orders for each
customer is displayed, including the order-detail-records.

Problem is: How do I filter my resultset, displaying only customers
which have more than 2 orders.
Otherwise in SQL:

select c.customerid, count(o.orderid)
from [customer] c
inner join [order] o
on o.customerid = c.customerid
group by c.customerid
HAVING count(o.orderid) >2

Hope someone can help me out.

Regards,
Twan Kennis

--------------------------------------------------------------
SKB Vragenlijst Services
Postbus 12354, 1100 AJ Amsterdam
Bezoekadres J. Geesinkweg 821, 1096 AZ Amsterdam
Telefoon 020 462 78 90, Fax 020 462 78 99
E-mail computer (AT) skb (DOT) nl, Website www.skb.nl



Reply With Quote
  #2  
Old   
Twan Kennis
 
Posts: n/a

Default Re: filtering resultset on summary field (one part solved, one part remaining) - 12-12-2006 , 11:52 AM






Found out 1 part of the solution myself, one part to solve.

table [order]
"orderid" = number
"customerid" = number
"const" = calculated field: =1
"date" = date field

relationship: [Order].customerid = [Customer].customerid

table [customer]
"customerid" = number
"ordercount" = calculated field: Count(order::const)

relationship: [Customer].customerid = [Order].customerid

Because of the relationship backwards (customer --> order), the number
of orders for a specific customer can be counted by presenting the
calcultaed field "ordercount".

The part to solve:

The counted number of orders for a specific customer is always a total
count for all records.
How to present the number of orders per customer, bought within a
specific (user selectable) date-range.

Regards, Twan
SKB Vragenlijst Services, automatisering




"Twan Kennis" <computer (AT) skb (DOT) nl> wrote

Quote:
Have some slight problem filtering my data based on a summary field.

Situation:
2 databases: [customer], [order]
each record in database [order] has a customerid , which is the
foreign
key to database [customer]
database [order] has also a counted summary field "number_of_orders".

I have a report, which groups by all orders based on a customer.
In the group-by header (print-layout), the number of orders for each
customer is displayed, including the order-detail-records.

Problem is: How do I filter my resultset, displaying only customers
which have more than 2 orders.
Otherwise in SQL:

select c.customerid, count(o.orderid)
from [customer] c
inner join [order] o
on o.customerid = c.customerid
group by c.customerid
HAVING count(o.orderid) >2

Hope someone can help me out.

Regards,
Twan Kennis

--------------------------------------------------------------
SKB Vragenlijst Services
Postbus 12354, 1100 AJ Amsterdam
Bezoekadres J. Geesinkweg 821, 1096 AZ Amsterdam
Telefoon 020 462 78 90, Fax 020 462 78 99
E-mail computer (AT) skb (DOT) nl, Website www.skb.nl





Reply With Quote
  #3  
Old   
Helpful Harry
 
Posts: n/a

Default Re: filtering resultset on summary field (one part solved, one part remaining) - 12-13-2006 , 12:19 AM



In article <12ntr32nval3658 (AT) corp (DOT) supernews.com>, "Twan Kennis"
<computer (AT) skb (DOT) nl> wrote:

Quote:
Found out 1 part of the solution myself, one part to solve.

table [order]
"orderid" = number
"customerid" = number
"const" = calculated field: =1
"date" = date field

relationship: [Order].customerid = [Customer].customerid

table [customer]
"customerid" = number
"ordercount" = calculated field: Count(order::const)

relationship: [Customer].customerid = [Order].customerid

Because of the relationship backwards (customer --> order), the number
of orders for a specific customer can be counted by presenting the
calcultaed field "ordercount".

The part to solve:

The counted number of orders for a specific customer is always a total
count for all records.
How to present the number of orders per customer, bought within a
specific (user selectable) date-range.

Create three new fields in the Order table:

g_StartDate Global, Date

g_EndDate Global, Date

c_InDateRange Calculation, Number result
= If((Date < g_StartDate) or (Date > g_EndDate),
0,
1)

Then change you OrderCount field to sum this new Calculation field.
ie.
OrderCount Calculation, Number result
= Sum(Order::c_InDateRange)

This field will now give you a total of the number of Order records a
customer has, but only for dates between the dates entered into
g_StartDate and g_EndDate.


Now, to Find the orders to print the report on you can simply:

- Enter the first date of the date range into the g_StartDate field

- Enter the last date of the date range into the g_EndDate field

- Perform a Find putting ">1" (or ">=2") into the OrderCount field

You should get a found set that contains only the Order records for
customers that have 2 or more orders between the two dates.


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #4  
Old   
Twan Kennis
 
Posts: n/a

Default Re: filtering resultset on summary field (one part solved, one part remaining) - 12-14-2006 , 03:22 AM



Tremendously found!

Twan


"Helpful Harry" <helpful_harry (AT) nom (DOT) de.plume.com> wrote

Quote:
In article <12ntr32nval3658 (AT) corp (DOT) supernews.com>, "Twan Kennis"
computer (AT) skb (DOT) nl> wrote:

Found out 1 part of the solution myself, one part to solve.

table [order]
"orderid" = number
"customerid" = number
"const" = calculated field: =1
"date" = date field

relationship: [Order].customerid = [Customer].customerid

table [customer]
"customerid" = number
"ordercount" = calculated field: Count(order::const)

relationship: [Customer].customerid = [Order].customerid

Because of the relationship backwards (customer --> order), the
number
of orders for a specific customer can be counted by presenting the
calcultaed field "ordercount".

The part to solve:

The counted number of orders for a specific customer is always a
total
count for all records.
How to present the number of orders per customer, bought within a
specific (user selectable) date-range.


Create three new fields in the Order table:

g_StartDate Global, Date

g_EndDate Global, Date

c_InDateRange Calculation, Number result
= If((Date < g_StartDate) or (Date > g_EndDate),
0,
1)

Then change you OrderCount field to sum this new Calculation field.
ie.
OrderCount Calculation, Number result
= Sum(Order::c_InDateRange)

This field will now give you a total of the number of Order records a
customer has, but only for dates between the dates entered into
g_StartDate and g_EndDate.


Now, to Find the orders to print the report on you can simply:

- Enter the first date of the date range into the g_StartDate field

- Enter the last date of the date range into the g_EndDate field

- Perform a Find putting ">1" (or ">=2") into the OrderCount field

You should get a found set that contains only the Order records for
customers that have 2 or more orders between the two dates.


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships
;o)




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.