Deepak Kumar Posted May 21, 2013 Posted May 21, 2013 Hi all,  Scenario: I have Product and Customer table. I have some records in Product table, having  fields, Product_name, Product_Category, Product_customer.  And also i have some records in Customer table.  e.g, Product table having 5 products. I have 3 transport as Product_category, 2 location as Product_category. John, as value in Product_customer field, in all 5 records.   Now , i want to calculate the maximum occurrence of Product_Category of a each customer in Customer table.  Output should be Transport.  Please see screenshot as reference.
rivet Posted May 21, 2013 Posted May 21, 2013 1. When you say maximum occurrence, do mean you would like a count for each category? 2. FMP11 or FMP12?
Deepak Kumar Posted May 22, 2013 Author Posted May 22, 2013 It is fmp12. Suppose there is a customer, John, which has 3 transport and 2 Location as Product category. Since , transport is maximum, i want to to calculate transport / the maximim occurrence of values for a customer in Product_category.
Solution rivet Posted May 22, 2013 Solution Posted May 22, 2013 If I understand correctly. 1. I would count each category for that client, sort descending using the ExecuteSql function, 2. then take the first line returned with GetValue. ExecuteSQL ( " SELECT p.category, count ( p.category) AS total FROM product p WHERE p.id_customer = ? GROUP BY p.category ORDER BY total DESC " ; " " ; "¶" ; customer::id ) This will return a sorted array with the highest count at the top of the list, which you can grab with GetValue function. 1
Recommended Posts
This topic is 4213 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now