


Dev Articles Community Forums
> Programming
> Java Development

How to calculate the sets of a set, ordered set, generic set?
Discuss How to calculate the sets of a set, ordered set, generic set? in the Java Development forum on Dev Articles. How to calculate the sets of a set, ordered set, generic set? Java Development forum discussing Java, JSP, J2ME. Get help with Java and all of its related languages, libraries and variations. If it’s Javarelated, you can discuss it here.






Dev Articles Community Forums Sponsor:


July 21st, 2013, 10:16 PM

Registered User


Join Date: Jun 2013
Posts: 2
Time spent in forums: 1 h 13 m 17 sec
Reputation Power: 0


How to calculate the sets of a set, ordered set, generic set?
How to represent the sets of a set, ordered set, generic set? Many operations on sets are hard to implement through SQL. Moreover, the computation is not limited on database, such as the data from Excel and even there is no database in the application environment. In this case, how do you deal with it?
Let’s check it out with this example: a sales department needs to make statistics on the outstanding salesmen who account for half of the total sales based on their sales records.
With esProc, it can dealt with as follows,
A B
1=$select*from salesOrder
2=A1.group(name;name,~.sum(sales):salesSum)
3=A2.sort@0(salesSum:1) =A2.sum(salesSum)/2
4=A3.derive(A3.(salesSum).cumulate()(#):addup)
5=A4.select(addup<=B3(addup>B3&&addup[1]<B3))
With R, it can be dealt with like:
01 library(RODBC)
02 odbcDataSources()
03 conn<odbcConnect("sqlsvr")
04 originalData<sqlQuery(conn,'select * from salesOrder')
05 odbcClose(conn)
06 nameSum<aggregate(originalData$sales,list(originalData$nam e),sum)
07 names(nameSum)<c('name','salesSum')
08 orderData<nameSum[rev(order(nameSum$salesSum)),]
09 halfSum<sum(orderData$salesSum)/2
10 orderData$addup<cumsum(orderData$salesSum)
11 subset(orderData,addup<=halfSum  (addup>halfSum & c( 0, addup[ length (addup)]) <halfSum))
Do you have any other ways?

Developer Shed Advertisers and Affiliates
Thread Tools 
Search this Thread 


Display Modes 
Rate This Thread 
Linear Mode


Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off




