I have a file containing following entries;
Changing to: /Out/AP/SD
sftp> ls -lrt
-rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_M.csv
-rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_S.csv
-rw-rw-rw- 1 user group 1724355981 Oct 25 10:24 HOLD_201810261310.csv
-rw-rw-rw- 1 user group 2319514056 Oct 25 10:26 FINAL_201810261347.csv
-rw-rw-rw- 1 user group 0 Oct 25 10:26 SUMMARY_201810261343.csv
-rw-rw-rw- 1 user group 0 Oct 26 10:16 HOLD_201810271245_S.csv
-rw-rw-rw- 1 user group 0 Oct 26 10:16 HOLD_201810271246_M.csv
-rw-rw-rw- 1 user group 1725252957 Oct 26 10:17 HOLD_201810271302.csv
-rw-rw-rw- 1 user group 2244889790 Oct 26 10:21 FINAL_201810271346.csv
-rw-rw-rw- 1 user group 0 Oct 26 10:21 SUMMARY_201810271342.csv
sftp> bye
Changing to: /Out/AS/SD
sftp> ls -lrt
-rw-rw-rw- 1 user group 174172077 Oct 25 13:01 HOLD_201810261753.csv
-rw-rw-rw- 1 user group 191231356 Oct 25 13:01 HOLD_201810261753_M.csv
-rw-rw-rw- 1 user group 177010167 Oct 25 13:01 HOLD_201810261753_S.csv
-rw-rw-rw- 1 user group 171490539 Oct 25 13:02 FINAL_201810261808.csv
-rw-rw-rw- 1 user group 0 Oct 25 13:02 SUMMARY_201810261808.csv
-rw-rw-rw- 1 user group 97238298 Oct 25 13:02 VAS_HOLD_201810261751.csv
sftp> bye
Changing to: /Out/BR/SD
sftp> ls -lrt
-rw-rw-rw- 1 user group 0 Oct 25 11:24 HOLD_201810261529_S.csv
-rw-rw-rw- 1 user group 1721060436 Oct 25 11:25 HOLD_201810261544_M.csv
-rw-rw-rw- 1 user group 1537619643 Oct 25 11:26 HOLD_201810261546.csv
-rw-rw-rw- 1 user group 1545973081 Oct 25 11:28 FINAL_201810261601.csv
-rw-rw-rw- 1 user group 0 Oct 25 11:28 SUMMARY_201810261559.csv
sftp> bye
I want to print all lines between sftp> ls -lrt and sftp> bye which i can get using
awk '/sftp> ls -lrt/{flag=1;next}/sftp> bye/{flag=0}flag' filename
but i want to print data as;
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_M.csv
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_S.csv
/Out/AP/SD -rw-rw-rw- 1 user group 1724355981 Oct 25 10:24 HOLD_201810261310.csv
.........
/Out/AS/SD -rw-rw-rw- 1 user group 174172077 Oct 25 13:01 HOLD_201810261753.csv
/Out/AS/SD -rw-rw-rw- 1 user group 191231356 Oct 25 13:01 HOLD_201810261753_M.csv
and so on...
Thank for your support...
Here it is multi line output excluding lines without a character:
$ awk '/^Changing to: / { match($0,/^Changing to: /); dir=substr($0,RLENGTH+1); } /^sftp> ls -lrt$/ { doprint=1; next; } /^sftp> bye$/ { doprint=0; } /.+/ { if ( doprint == 1 ) print(dir " " $0); }' sftp.out
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_M.csv
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_S.csv
/Out/AP/SD -rw-rw-rw- 1 user group 1724355981 Oct 25 10:24 HOLD_201810261310.csv
/Out/AP/SD -rw-rw-rw- 1 user group 2319514056 Oct 25 10:26 FINAL_201810261347.csv
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 25 10:26 SUMMARY_201810261343.csv
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 26 10:16 HOLD_201810271245_S.csv
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 26 10:16 HOLD_201810271246_M.csv
/Out/AP/SD -rw-rw-rw- 1 user group 1725252957 Oct 26 10:17 HOLD_201810271302.csv
/Out/AP/SD -rw-rw-rw- 1 user group 2244889790 Oct 26 10:21 FINAL_201810271346.csv
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 26 10:21 SUMMARY_201810271342.csv
/Out/AS/SD -rw-rw-rw- 1 user group 174172077 Oct 25 13:01 HOLD_201810261753.csv
/Out/AS/SD -rw-rw-rw- 1 user group 191231356 Oct 25 13:01 HOLD_201810261753_M.csv
/Out/AS/SD -rw-rw-rw- 1 user group 177010167 Oct 25 13:01 HOLD_201810261753_S.csv
/Out/AS/SD -rw-rw-rw- 1 user group 171490539 Oct 25 13:02 FINAL_201810261808.csv
/Out/AS/SD -rw-rw-rw- 1 user group 0 Oct 25 13:02 SUMMARY_201810261808.csv
/Out/AS/SD -rw-rw-rw- 1 user group 97238298 Oct 25 13:02 VAS_HOLD_201810261751.csv
/Out/BR/SD -rw-rw-rw- 1 user group 0 Oct 25 11:24 HOLD_201810261529_S.csv
/Out/BR/SD -rw-rw-rw- 1 user group 1721060436 Oct 25 11:25 HOLD_201810261544_M.csv
/Out/BR/SD -rw-rw-rw- 1 user group 1537619643 Oct 25 11:26 HOLD_201810261546.csv
/Out/BR/SD -rw-rw-rw- 1 user group 1545973081 Oct 25 11:28 FINAL_201810261601.csv
/Out/BR/SD -rw-rw-rw- 1 user group 0 Oct 25 11:28 SUMMARY_201810261559.csv
If You need as one line output as it was in original question:
$ awk '/^Changing to: / { match($0,/^Changing to: /); printf("%s ",substr($0,RLENGTH+1)); } /^sftp> ls -lrt$/ { doprint=1; next; } /^sftp> bye$/ { doprint=0; } /.+/ { if (doprint == 1) printf("%s ",$0); } END { print(""); }' sftp.out
/Out/AP/SD -rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_M.csv -rw-rw-rw- 1 user group 0 Oct 25 10:24 HOLD_201810261247_S.csv -rw-rw-rw- 1 user group 1724355981 Oct 25 10:24 HOLD_201810261310.csv -rw-rw-rw- 1 user group 2319514056 Oct 25 10:26 FINAL_201810261347.csv -rw-rw-rw- 1 user group 0 Oct 25 10:26 SUMMARY_201810261343.csv -rw-rw-rw- 1 user group 0 Oct 26 10:16 HOLD_201810271245_S.csv -rw-rw-rw- 1 user group 0 Oct 26 10:16 HOLD_201810271246_M.csv -rw-rw-rw- 1 user group 1725252957 Oct 26 10:17 HOLD_201810271302.csv -rw-rw-rw- 1 user group 2244889790 Oct 26 10:21 FINAL_201810271346.csv -rw-rw-rw- 1 user group 0 Oct 26 10:21 SUMMARY_201810271342.csv /Out/AS/SD -rw-rw-rw- 1 user group 174172077 Oct 25 13:01 HOLD_201810261753.csv -rw-rw-rw- 1 user group 191231356 Oct 25 13:01 HOLD_201810261753_M.csv -rw-rw-rw- 1 user group 177010167 Oct 25 13:01 HOLD_201810261753_S.csv -rw-rw-rw- 1 user group 171490539 Oct 25 13:02 FINAL_201810261808.csv -rw-rw-rw- 1 user group 0 Oct 25 13:02 SUMMARY_201810261808.csv -rw-rw-rw- 1 user group 97238298 Oct 25 13:02 VAS_HOLD_201810261751.csv /Out/BR/SD -rw-rw-rw- 1 user group 0 Oct 25 11:24 HOLD_201810261529_S.csv -rw-rw-rw- 1 user group 1721060436 Oct 25 11:25 HOLD_201810261544_M.csv -rw-rw-rw- 1 user group 1537619643 Oct 25 11:26 HOLD_201810261546.csv -rw-rw-rw- 1 user group 1545973081 Oct 25 11:28 FINAL_201810261601.csv -rw-rw-rw- 1 user group 0 Oct 25 11:28 SUMMARY_201810261559.csv
note there is added space and new line in the end
Related
I'm trying to extract the name of space organisations from a table but the closest i can get is the amount of times it appears next to the name of the organisation but i just want the name of the organisation not the amount of times it is named in the table.
if you can help me please leave a comment on my google colab.
https://colab.research.google.com/drive/1m4zI4YGguQ5aWdDVyc7Bdpr-78KHdxhR?usp=sharing
What I get:
variable number
organisation
time of launch
0
SpaceX
Fri Aug 07, 2020 05:12 UTC
1
CASC
Thu Aug 06, 2020 04:01 UTC
2
SpaceX
Tue Aug 04, 2020 23:57 UTC
3
Roscosmos
Thu Jul 30, 2020 21:25 UTC
4
ULA
Thu Jul 30, 2020 11:50 UTC
...
...
...
4319
US Navy
Wed Feb 05, 1958 07:33 UTC
4320
AMBA
Sat Feb 01, 1958 03:48 UTC
4321
US Navy
Fri Dec 06, 1957 16:44 UTC
4322
RVSN USSR
Sun Nov 03, 1957 02:30 UTC
4323
RVSN USSR
Fri Oct 04, 1957 19:28 UTC
etc
etc
etc
What I want:
organisation
RVSN USSR
Arianespace
CASC
General Dynamics
NASA
VKS RF
US Air Force
ULA
Boeing
Martin Marietta
etc
How do I simply group by a 24 hour interval from 7am to 7am in a manner similar to:
select format(t_stamp,'yyyy-MMM')
from mytable
group by format(t_stamp,'yyyy-MMM')
if input is like
3,Wed Mar 23 20:40:40 EDT 2022
3,Wed Mar 23 20:40:39 EDT 2022
4,Wed Mar 23 03:36:10 EDT 2022
3,Wed Mar 22 15:46:44 EST 2022
3,Tue Mar 22 04:16:52 EST 2022
4,Sat Mar 22 03:13:08 EDT 2022
3,Sat Mar 22 03:13:05 EDT 2022
4,Sat Mar 21 04:10:36 EDT 2022
output should be like
6, Mar 23
7, Mar 22
10, Mar 21
4, Mar 20
How could I calculate a field based on values from previous and next rows?
I have this list from users with a date (month and year) and a field indicating if the user has 1+ purchases in that month-year
id_user
Date
Has_purchases
Active
15678
Jan 2021
0
1
15678
feb 2021
1
1
15678
mar 2021
0
1
15678
Apr 2021
0
1
15678
may 2021
0
0
15678
jun 2021
0
1
15678
jul 2021
0
1
15678
Aug 2021
1
1
15678
sep 2021
0
1
15678
oct 2021
0
1
15678
nov 2021
0
1
15678
Dec 2021
1
1
I need to calculate if the user was active on a date (month-year). An active user is defined as an user who has at least one purchase on the last 3 months.
Eg. User 15678 is 'active' on march because user has purchases on february, the same user in unactive on may beacause it does not have purchases on march and april and also does not have purchases on june and july
I've written a query that returns the size of my individual records in mb. These records contain Blob data.
I would like to partition the records in 50mb batches.
SELECT SourceId, Title, Description,
SUM(DATALENGTH(VersionData) * 0.000001) OVER (PARTITION BY DATALENGTH(SourceId) ORDER BY SourceId) AS RunningTotal,
RANK() OVER(ORDER BY SourceId) AS RowNo
FROM TargetContentVersion WITH(NOLOCK)
The data returned from this query currently looks like this, where RunningTotal is the running total in mb of the records:
SourceId Title RunningTotalRowNo
00Pf4000006gna3EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_37_32).pdf 5.242880 1
00Pf4000006gna8EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_37_38).doc 6.291456 2
00Pf4000006gnacEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_38_44).pdf 7.340032 3
00Pf4000006gnaDEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_41).doc 12.582912 4
00Pf4000006gnahEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_38_47).pdf 17.825792 5
00Pf4000006gnaIEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_46).doc 23.068672 6
00Pf4000006gnamEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_38_54).pdf 33.554432 7
00Pf4000006gnaNEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_52).txt 34.603008 8
00Pf4000006gnarEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_20).doc 35.651584 9
00Pf4000006gnaSEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_55).txt 40.894464 10
00Pf4000006gnawEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_24).doc 46.137344 11
00Pf4000006gnaXEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_38_0).txt 51.380224 12
00Pf4000006gnb1EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_30).doc 61.865984 13
00Pf4000006gnb6EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_50).txt 62.914560 14
00Pf4000006gnbaEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_29).doc 68.157440 15
00Pf4000006gnbBEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_39_58).txt 78.643200 16
00Pf4000006gnbfEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_34).doc 89.128960 17
00Pf4000006gnbGEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_7).pdf 90.177536 18
00Pf4000006gnbkEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_43).txt 91.226112 19
00Pf4000006gnbLEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_12).pdf 96.468992 20
00Pf4000006gnbpEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_46).txt 101.711872 21
00Pf4000006gnbQEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_17).pdf 112.197632 22
00Pf4000006gnbuEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_52).txt 122.683392 23
00Pf4000006gnbVEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_26).doc 123.731968 24
00Pf4000006gnbzEAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_0).pdf 124.780544 25
00Pf4000006gnc4EAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_5).pdf 130.023424 26
00Pf4000006gnc9EAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_11).pdf 140.509184 27
00Pf4000006gncdEAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_56).txt 145.752064 28
00Pf4000006gncEEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_30).doc 146.800640 29
00Pf4000006gnciEAA 001f400000ZP5yWAAT_3 Oct 2018 (14_42_3).txt 157.286400 30
00Pf4000006gncJEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_33).doc 162.529280 31
00Pf4000006gncKEAQ 001f400000ZP5ycAAD_3 Oct 2018 (14_48_11).txt 173.015040 32
00Pf4000006gncnEAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_12).pdf 174.063616 33
00Pf4000006gncsEAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_15).pdf 179.306496 34
00Pf4000006gncTEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_44).doc 189.792256 35
00Pf4000006gncxEAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_30).pdf 200.278016 36
00Pf4000006gncYEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_53).txt 201.326592 37
00Pf4000006gnd2EAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_46).doc 202.375168 38
00Pf4000006gnd7EAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_49).doc 207.618048 39
00Pf4000006gndbEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_23).pdf 212.860928 40
00Pf4000006gndCEAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_42_54).doc 223.346688 41
00Pf4000006gndgEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_30).pdf 233.832448 42
00Pf4000006gnDhEAI Snake_River_(5mb).jpg 239.077777 43
00Pf4000006gndHEAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_43_3).txt 240.126353 44
00Pf4000006gndlEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_39).doc 241.174929 45
00Pf4000006gndMEAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_43_6).txt 246.417809 46
00Pf4000006gndqEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_41).doc 251.660689 47
00Pf4000006gnDrEAI Pizigani_1367_Chart_10MB.jpg 261.835395 48
00Pf4000006gndREAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_43_11).txt 272.321155 49
00Pf4000006gndvEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_47).doc 282.806915 50
00Pf4000006gnDwEAI Spinner_Dolphin_Indian_Ocean_07-2017.jpg 284.109019 51
00Pf4000006gndWEAQ 001f400000ZP5yYAAT_3 Oct 2018 (14_43_20).pdf 285.157595 52
00Pf4000006gnDXEAY 440 Kb.jpg 285.609143 53
00Pf4000006gne0EAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_59).txt 286.657719 54
00Pf4000006gne5EAA 001f400000ZP5yYAAT_3 Oct 2018 (14_44_2).txt 291.900599 55
00Pf4000006gneaEAA 001f400000ZP5yZAAT_3 Oct 2018 (14_44_59).txt 302.386359 56
00Pf4000006gneAEAQ 001f400000ZP5yYAAT_3 Oct 2018 (14_44_7).txt 312.872119 57
00Pf4000006gneeEAA 001f400000ZP5yZAAT_3 Oct 2018 (14_44_40).doc 323.357879 58
I would like the results to look like this where they are partitioned in 50mb batches:
SourceId Title RunningTotalRowNo Batch
00Pf4000006gna3EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_37_32).pdf 5.242880 1 1
00Pf4000006gna8EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_37_38).doc 6.291456 2 1
00Pf4000006gnacEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_38_44).pdf 7.340032 3 1
00Pf4000006gnaDEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_41).doc 12.582912 4 1
00Pf4000006gnahEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_38_47).pdf 17.825792 5 1
00Pf4000006gnaIEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_46).doc 23.068672 6 1
00Pf4000006gnamEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_38_54).pdf 33.554432 7 1
00Pf4000006gnaNEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_52).txt 34.603008 8 1
00Pf4000006gnarEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_20).doc 35.651584 9 1
00Pf4000006gnaSEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_37_55).txt 40.894464 10 1
00Pf4000006gnawEAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_24).doc 46.137344 11 1
00Pf4000006gnaXEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_38_0).txt 51.380224 12 1
00Pf4000006gnb1EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_30).doc 61.865984 13 2
00Pf4000006gnb6EAA 001f400000ZP5yUAAT_3 Oct 2018 (14_39_50).txt 62.914560 14 2
00Pf4000006gnbaEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_29).doc 68.157440 15 2
00Pf4000006gnbBEAQ 001f400000ZP5yUAAT_3 Oct 2018 (14_39_58).txt 78.643200 16 2
00Pf4000006gnbfEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_34).doc 89.128960 17 2
00Pf4000006gnbGEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_7).pdf 90.177536 18 2
00Pf4000006gnbkEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_43).txt 91.226112 19 2
00Pf4000006gnbLEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_12).pdf 96.468992 20 2
00Pf4000006gnbpEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_46).txt 101.711872 21 3
00Pf4000006gnbQEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_17).pdf 112.197632 22 3
00Pf4000006gnbuEAA 001f400000ZP5yVAAT_3 Oct 2018 (14_40_52).txt 122.683392 23 3
00Pf4000006gnbVEAQ 001f400000ZP5yVAAT_3 Oct 2018 (14_40_26).doc 123.731968 24 3
00Pf4000006gnbzEAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_0).pdf 124.780544 25 3
00Pf4000006gnc4EAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_5).pdf 130.023424 26 3
00Pf4000006gnc9EAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_11).pdf 140.509184 27 3
00Pf4000006gncdEAA 001f400000ZP5yWAAT_3 Oct 2018 (14_41_56).txt 145.752064 28 3
00Pf4000006gncEEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_30).doc 146.800640 29 3
00Pf4000006gnciEAA 001f400000ZP5yWAAT_3 Oct 2018 (14_42_3).txt 157.286400 30 4
00Pf4000006gncJEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_33).doc 162.529280 31 4
00Pf4000006gncKEAQ 001f400000ZP5ycAAD_3 Oct 2018 (14_48_11).txt 173.015040 32 4
00Pf4000006gncnEAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_12).pdf 174.063616 33 4
00Pf4000006gncsEAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_15).pdf 179.306496 34 4
00Pf4000006gncTEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_44).doc 189.792256 35 4
00Pf4000006gncxEAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_30).pdf 200.278016 36 5
00Pf4000006gncYEAQ 001f400000ZP5yWAAT_3 Oct 2018 (14_41_53).txt 201.326592 37 5
00Pf4000006gnd2EAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_46).doc 202.375168 38 5
00Pf4000006gnd7EAA 001f400000ZP5yXAAT_3 Oct 2018 (14_42_49).doc 207.618048 39 5
00Pf4000006gndbEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_23).pdf 212.860928 40 5
00Pf4000006gndCEAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_42_54).doc 223.346688 41 5
00Pf4000006gndgEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_30).pdf 233.832448 42 5
00Pf4000006gnDhEAI Snake_River_(5mb).jpg 239.077777 43 5
00Pf4000006gndHEAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_43_3).txt 240.126353 44 5
00Pf4000006gndlEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_39).doc 241.174929 45 5
00Pf4000006gndMEAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_43_6).txt 246.417809 46 5
00Pf4000006gndqEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_41).doc 251.660689 47 6
00Pf4000006gnDrEAI Pizigani_1367_Chart_10MB.jpg 261.835395 48 6
00Pf4000006gndREAQ 001f400000ZP5yXAAT_3 Oct 2018 (14_43_11).txt 272.321155 49 6
00Pf4000006gndvEAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_47).doc 282.806915 50 6
00Pf4000006gnDwEAI Spinner_Dolphin_Indian_Ocean_07-2017.jpg 284.109019 51 6
00Pf4000006gndWEAQ 001f400000ZP5yYAAT_3 Oct 2018 (14_43_20).pdf 285.157595 52 6
00Pf4000006gnDXEAY 440 Kb.jpg 285.609143 53
00Pf4000006gne0EAA 001f400000ZP5yYAAT_3 Oct 2018 (14_43_59).txt 286.657719 54 6
00Pf4000006gne5EAA 001f400000ZP5yYAAT_3 Oct 2018 (14_44_2).txt 291.900599 55 6
00Pf4000006gneaEAA 001f400000ZP5yZAAT_3 Oct 2018 (14_44_59).txt 302.386359 56 7
00Pf4000006gneAEAQ 001f400000ZP5yYAAT_3 Oct 2018 (14_44_7).txt 312.872119 57 7
00Pf4000006gneeEAA 001f400000ZP5yZAAT_3 Oct 2018 (14_44_40).doc 323.357879 58 7
Help would be much appreciated, thank you.
You can use integer division:
SELECT ( CAST ( SUM(Datalength(versiondata) * 0.000001)
OVER (
partition BY Datalength(sourceid)
ORDER BY sourceid) AS INT) / 50 ) + 1 AS Batch
FROM TargetContentVersion
Here's a quick sample that demonstrates how it works:
CREATE TABLE #t (id INT IDENTITY(1,1), size NUMERIC(8,6))
GO
INSERT INTO #t
SELECT RAND() * 20
GO 20 -- Create 20 sample rows with random sizes between 0 and 20
SELECT id, SUM(size) OVER (ORDER BY id) AS RunningTotal,
(CAST(SUM(size) OVER (ORDER BY id) AS INT) / 50) + 1 AS Batch
FROM #t
id RunningTotal Batch
1 2.303367 1
2 4.049776 1
3 19.177784 1
4 28.637981 1
5 29.675840 1
6 32.781603 1
7 33.859586 1
8 36.633733 1
9 39.413363 1
10 58.004502 2
11 70.363837 2
12 82.897268 2
13 83.946657 2
14 85.623044 2
15 87.432670 2
16 103.304830 3
17 103.709745 3
18 122.165664 3
19 126.554616 3
20 128.019929 3
I've worked it out.
Script below for those interested.
WITH cte1 AS (
SELECT SourceId, Title, DATALENGTH(VersionData) * 0.000001 AS RecordSize,
CAST(SUM(DATALENGTH(VersionData) * 0.000001) OVER (PARTITION BY
DATALENGTH(SourceId) ORDER BY SourceId) AS INT) AS RunningTotal,
RANK() OVER(ORDER BY SourceId) AS RowNo
FROM TargetContentVersion WITH(NOLOCK)
)
SELECT SourceId, Title, RecordSize, RunningTotal,
RowNo, SUM(RunningTotal) OVER (PARTITION BY SourceId ORDER BY SourceId) / 50 AS
Batch
FROM cte1
Another option would be to use dense_rank:
WITH CTE AS
(
SELECT SourceId, Title, Description,
SUM(DATALENGTH(VersionData) * 0.000001) OVER (PARTITION BY DATALENGTH(SourceId) ORDER BY SourceId) AS RunningTotal,
RANK() OVER(ORDER BY SourceId) AS RowNo
FROM TargetContentVersion WITH(NOLOCK)
)
SELECT SourceId, Title, Description, RunningTotal, RowNo
DENSE_RANK() OVER(PARTITION BY SourceId ORDER BY CAST(RunningTotal as int) / 50) As Batch
from #CTE
Note the casting of RunningTotal to int.
I have following data:
Table1:
Code code_id day
F23 123df 16 Jul 2016
F23 123df 17 Jul 2016
F23 123df 18 Jul 2016
F23 123df 19 Jul 2016
F23 123df 20 Jul 2016
F24 124df 16 Jul 2016
F24 124df 17 Jul 2016
F24 124df 18 Jul 2016
F24 124df 19 Jul 2016
F24 124df 20 Jul 2016
Table2:
Code code_id status daytime End_date
F23 123df down 16 Jul 2016 06:00 am 18 Jul 2016 08:00 pm
F23 123df down 19 Jul 2016 05:00 am 21 Jul 2016 03:45 pm
F23 123df down 23 Jul 2016 02:40 am
I need to select data from table1 where day not in between of daytime and End_date from table2 and if table1 day (like '16 Jul 2016' is the same day as '16 Jul 2016 06:00' from table2) is like table2 day from daytime or End_date fields then it still has to select data for this day. In case of End_date is null then it has to be sysdate - nvl(End_date,sysdate).
For example when select for day = '16 Jul 2016' from table1 it has to be:
F23 123df 16 Jul 2016
F24 124df 16 Jul 2016
But when select for '17 Jul 2016' then it has to be:
F24 124df 17 Jul 2016
When select for '18 Jul 2016' it has to be:
F23 123df 18 Jul 2016
F24 124df 18 Jul 2016
thanks,
S
SELECT *
FROM table1 t
WHERE NOT EXISTS (
SELECT 1
FROM table2 x
WHERE t.code = x.code
AND t.code_id = x.code_id
AND t.day >= x.daytime
AND t.day + INTERVAL '86399' SECOND <= x.end_date
);