JSL查詢:在同一列中查找相同的名稱行,然後比較日期並查找以後的日期
大家好,
我有一個數據表,我想比較,
1。SN列首先查找是否有相同的名稱行,
2。然後比較相同的名稱行,找到哪一行在“date1”列上的日期更晚,
3。然後將該行指定為“1”到列LLR。
我使用下面的腳本,但不起作用,我不知道如何調試它,任何人都可以幫助我學習?
dt = Current Data Table();
New Column( "LLR");
For( i = 1, i <= N Row( dt ), i++,
SNcol = Column( dt, "SN" )[i];
Datecol = Column( dt, "DATE1" )[i];
For( j = 1, j <= N Row( dt ), j++,
If( Column( dt, "SN" )[j] == SNcol,
Column( dt, "DATE1" )[j]>Column( dt, "DATE1" )[i],"1"
"0")));

Re:JSL查詢:在同一列中查找同一行,然後比較日期並查找以後的日期不確定你想要什麼,但你可以嘗試使用Col Max()函數的列公式,在SN之後分組。
兩個例子:
dt = Current Data Table();
// Returns 1 for max DATE of each SN
dt << New Column("LLR", Formula(If(Col Max(:DATE1, :SN) == :DATE1, 1)));
// Returns 1 for max DATE of each replicated SN
dt << New Column("LLR2", Formula(If(Col Max(:DATE1, :SN) == :DATE1 & Col Number(:SN, :SN) > 1, 1)));
Re:JSL查詢:在同一列中查找同一行,然後比較日期並查找以後的日期我不確定我是否完全理解你的要求。但是,如果我關閉,以下代碼可能會有所幫助。如果您從JSL開始,我建議您使用“幫助>腳本索引”來了解它的工作原理。另外,請記住,有很多方法可以做到這一點,這種方式可能會或可能不會比其他方式“更好”。
NamesDefaultToHere(1);
// Make a table to play with
dt = New Table( "Mark the Latest Date",
Add Rows( 25 ),
New Column( "Group",
Numeric,
"Nominal",
Format( "Best", 12 ),
Formula(RandomInteger(1, 5))
),
New Column( "DateTime",
Numeric,
"Continuous",
Format( "ddMonyyyy h:m:s", 22, 0 ),
Input Format( "ddMonyyyy h:m:s", 0 ),
Formula( Random Uniform( Today() - In Days( 7 ), Today() ) )
),
);
dt << runFormulas;
Column(dt, "Group") << deleteFormula;
dt << Sort(By(:Group), Replace Table);
// Start Here . . .
gVals = Column(dt, "Group") << getValues; // Values in the 'grouping' column
dtVals = Column(dt, "DateTime") << getValues; // Values in the 'DateTime' column
dt << NewColumn("Is Latest?", Numeric, Nominal, ValueLabels({0 = "No", 1 = "Yes"}), Values(J(NRow(dt), 1, 0))); // New column
// Loop over the groups
for(g=1, g<=Max(gVals), g++,
// Find which row the maximum for the current group is in
dtVals2 = dtVals; // Copy all the values
dtVals2[Loc(gVals != g)] = .; // Set values not corresponding to the current group to missing
r = LocMax(dtVals2); // Get the position (row number) of the maximum of the values that are left
// Overwrite the existing "0" value for this row
Column(dt, "Is Latest?")[r] = 1;
);Re:JSL查詢:在同一列中查找同一行,然後比較日期並查找以後的日期這是表格。
| SN |
DATE1 |
LLR |
LLR 2 |
| 一個 |
7/29/2017 12:27 |
1 |
|
| b |
9/1/2017 9:24 |
1 |
|
| b |
9/1/2017 9:25 |
1 |
|
| C |
9/4/2017 19:46 |
1 |
|
| C |
8/31/2017 23:22 |
1 |
|
| C |
9/4/2017 19:27 |
1 |
|