Comments (2)
Option 1
Customer id Segment Opened email in L3mths Clicked email L3mths
123 Unhealthy N N
456 Unhealthy Y N
789 Healthy Y Y
Option 2
Customer ID Number of emails received L3mths Number of emails opened L3mths Number of emails clicked L3mths
123 10 5 2
456 50 25 20
789 75 70 65
option 2 data are rollup with count where the actual column value is in date
**
for this if we used a sub query it will be easy but I need to**
DECLARE @in string = "/Input/test_data1.csv";//puting this file for test data
DECLARE @out string = "/Output/Crm_Click_Rpt.csv";
@input=
EXTRACT
EVENT_TYPE_ID String,
ACCOUNT_ID String,
LIST_ID String,
RI_ID String,
CUSTOMER_ID String,
EVENT_CAPTURED_DT DateTime,//puting as Open mail
EVENT_STORED_DT DateTime,//puting as Recived mail
CAMPAIGN_ID String,
LAUNCH_ID String,
EMAIL_id String,
EMAIL_ISP String,
EMAIL_FORMAT String,
OFFER_SIGNATURE_ID String,
DYNAMIC_CONTENT_SIGNATURE_ID String
FROM @in
USING Extractors.Text();
@requiredDate =
SELECT CUSTOMER_ID,
EVENT_CAPTURED_DT,
EVENT_STORED_DT
FROM @input;
//Create Input parameter CUSTOMER_ID wise to Class file ResponsysDataLakeAnalytics.Test.get_1
@m = SELECT CUSTOMER_ID,
ResponsysDataLakeAnalytics.Test.get_1(CUSTOMER_ID,EVENT_STORED_DT,EVENT_CAPTURED_DT) AS A
FROM @requiredDate;
//Split row with column
@e =
SELECT A.First().Split(',') [0]AS CUSTOMER_ID,
A.First().Split(',') [1]AS OPENED_EMAIL,
A.First().Split(',') [2]AS CLOSED_EMAIL
FROM @m;
//create collection of table record
@res =
SELECT CUSTOMER_ID,
SUM(int.Parse(OPENED_EMAIL)) AS om,
SUM(int.Parse(CLOSED_EMAIL)) AS cm,
COUNT( * ) AS t
FROM @e
GROUP BY CUSTOMER_ID;
//putting coumn Segment
@res =
SELECT CUSTOMER_ID,
om,
cm,
t,"Healthy" AS Segment
FROM @res WHERE om > 0 AND cm > 0
UNION
SELECT CUSTOMER_ID,
om,
cm,
t,"Unhealthy" AS Segment
FROM @res WHERE cm==0;
OUTPUT @res TO @out USING Outputters.Csv();
CS
public static SqlArray get_1(string customerID, DateTime mailedDate, DateTime openedDate)
{
if(DateTime.Compare(mailedDate, openedDate) ==0)
return new SqlArray(new[] {string.Concat(customerID,",",0,",",1) });
return new SqlArray(new[] { string.Concat(customerID,",",1,",",0) });
}
from usql.
I am not quite sure what your ask is. So I translated your T-SQL in the first message for now into U-SQL (note I removed the id column from the group by because it basically generated single row groups).
@t = SELECT * FROM (VALUES
( 123, "male", 1, 1, 22 ),
( 12, "female", 1, 2, 23 ),
( 123, "male", 2, 1, 22 ),
( 12, "female", 1, 1, 24 ),
( 111, "female", 1, 1, 23 ),
( 123, "female", 1, 4, 23)) AS T(id, gender, country, Orderi, age);
@count =
SELECT COUNT( * ) AS count
FROM @t;
@res =
SELECT gender,
country,
age,
string.Format("{0}%", COUNT(gender) * 100 /@count.count) AS Percent
FROM @t CROSS JOIN @count
GROUP BY gender,
country,
age, count;
OUTPUT @res
TO "/output/result.csv"
USING Outputters.Csv();
from usql.
Related Issues (20)
- JSON file with duplicate keys
- U-sql referenced assembly built with 4.5.1? Whereas documented 4.5 is needed HOT 11
- Any plans to open source the deployment / PackageDeploymentTool.exe?
- Legitimize the Microsoft.Analytics.Samples.Formats by removing "Samples" and moving out of the Examples folder HOT 1
- Retrieving the Properties Field using the Avro Extractor HOT 2
- Query to extract Key Value pair from Json HOT 1
- How to remove special characters in a column using usql
- Can this be used for outputting the headers from the Table Valued Function
- Update framework version or all .Net core
- Struggling to find a way to extract data between 2 strings
- are there examples showing how to convert csv to arvo? HOT 1
- Unable to install U-SQL Extensions HOT 5
- Local assembly registration
- Visual Studio: Local runs fail HOT 1
- Could not load type 'ScopeRuntime.ScopeDynamicPartitionedOutputCollector' error in local run HOT 2
- Is this project dead? HOT 2
- FAQ is a dead link HOT 1
- U-SQL reference documentation goes to a generic page HOT 1
- flowchart on stackedit
- test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usql.