How to split one column to multiple - sql

so my question is
run a query and get my result like this
WEEKS PRODUCT SELL
Week-1 Product-A 34
Week-1 Product-B 40
Week-1 Product-C 38
Week-1 Product-D 20
Week-2 Product-A 27
Week-2 Product-B 25
Week-2 Product-C 22
Week-2 Product-D 39
Week-3 Product-A 33
Week-3 Product-B 19
Week-3 Product-C 43
Week-3 Product-D 36
Week-4 Product-A 21
Week-4 Product-B 26
Week-4 Product-C 33
Week-4 Product-D 39
Week-5 Product-A 43
Week-5 Product-B 30
Week-5 Product-C 40
Week-5 Product-D 24
Week-6 Product-A 42
Week-6 Product-B 25
Week-6 Product-C 44
Week-6 Product-D 22
Week-7 Product-A 47
Week-7 Product-B 39
Week-7 Product-C 27
Week-7 Product-D 17
Week-8 Product-A 39
Week-8 Product-B 39
Week-8 Product-C 44
Week-8 Product-D 44
Week-9 Product-A 44
Week-9 Product-B 21
Week-9 Product-C 31
Week-9 Product-D 26
Week-10 Product-A 42
Week-10 Product-B 31
Week-10 Product-C 20
Week-10 Product-D 25
Week-11 Product-A 24
Week-11 Product-B 35
Week-11 Product-C 28
Week-11 Product-D 28
Week-12 Product-A 30
Week-12 Product-B 27
Week-12 Product-C 43
Week-12 Product-D 24
but i want my result like this
Week-1 Product-A 34 Product-B 40 Product-C 38 Product-D 20
Week-2 Product-A 27 Product-B 25 Product-C 22 Product-D 39
Week-3 Product-A 33 Product-B 19 Product-C 43 Product-D 36
Week-4 Product-A 21 Product-B 26 Product-C 33 Product-D 39
Week-5 Product-A 43 Product-B 30 Product-C 40 Product-D 24
Week-6 Product-A 42 Product-B 25 Product-C 44 Product-D 22
Week-7 Product-A 47 Product-B 39 Product-C 27 Product-D 17
Week-8 Product-A 39 Product-B 39 Product-C 44 Product-D 44
Week-9 Product-A 44 Product-B 21 Product-C 31 Product-D 26
Week-10 Product-A 42 Product-B 31 Product-C 20 Product-D 25
Week-11 Product-A 24 Product-B 35 Product-C 28 Product-D 28
Week-12 Product-A 30 Product-B 27 Product-C 43 Product-D 24
can i get my result like this
thank you

You can use conditional aggregation:
select weeks,
sum(case when product = 'Product-A' then sell end) as sell_a,
sum(case when product = 'Product-B' then sell end) as sell_b,
sum(case when product = 'Product-C' then sell end) as sell_c,
sum(case when product = 'Product-D' then sell end) as sell_d
from t
group by weeks
order by weeks;

Related

Save file from pixel values in .net core

There is a space-separated string contains 2304(48x48) items. I need simply save this as a 48x48 image file. Downloaded from here
var img = "70 80 82 72 58 58 60 63 54 58 60 48 89 115 121 119 115 110 98 91 84 84 90 99 110 126 143 153 158 171 169 172 169 165 129 110 113 107 95 79 66 62 56 57 61 52 43 41 65 61 58 57 56 69 75 70 65 56 54 105 146 154 151 151 155 155 150 147 147 148 152 158 164 172 177 182 186 189 188 190 188 180 167 116 95 103 97 77 72 62 55 58 54 56 52 44 50 43 54 64 63 71 68 64 52 66 119 156 161 164 163 164 167 168 170 174 175 176 178 179 183 187 190 195 197 198 197 198 195 191 190 145 86 100 90 65 57 60 54 51 41 49 56 47 38 44 63 55 46 52 54 55 83 138 157 158 165 168 172 171 173 176 179 179 180 182 185 187 189 189 192 197 200 199 196 198 200 198 197 177 91 87 96 58 58 59 51 42 37 41 47 45 37 35 36 30 41 47 59 94 141 159 161 161 164 170 171 172 176 178 179 182 183 183 187 189 192 192 194 195 200 200 199 199 200 201 197 193 111 71 108 69 55 61 51 42 43 56 54 44 24 29 31 45 61 72 100 136 150 159 163 162 163 170 172 171 174 177 177 180 187 186 187 189 192 192 194 195 196 197 199 200 201 200 197 201 137 58 98 92 57 62 53 47 41 40 51 43 24 35 52 63 75 104 129 143 149 158 162 164 166 171 173 172 174 178 178 179 187 188 188 191 193 194 195 198 199 199 197 198 197 197 197 201 164 52 78 87 69 58 56 50 54 39 44 42 26 31 49 65 91 119 134 145 147 152 159 163 167 171 170 169 174 178 178 179 187 187 185 187 190 188 187 191 197 201 199 199 200 197 196 197 182 58 62 77 61 60 55 49 59 52 54 44 22 30 47 68 102 123 136 144 148 150 153 157 167 172 173 170 171 177 179 178 186 190 186 189 196 193 191 194 190 190 192 197 201 203 199 194 189 69 48 74 56 60 57 50 59 59 51 41 20 34 47 79 111 132 139 143 145 147 150 151 160 169 172 171 167 171 177 177 174 180 182 181 192 196 189 192 198 195 194 196 198 201 202 195 189 70 39 69 61 61 61 53 59 59 45 40 26 40 61 93 124 135 138 142 144 146 151 152 158 165 168 168 165 161 164 173 172 167 172 167 180 198 198 193 199 195 194 198 200 198 197 195 190 65 35 68 59 59 62 57 60 59 50 44 32 54 90 115 132 137 138 140 144 146 146 156 165 168 174 176 176 175 168 168 169 171 175 171 172 192 194 184 198 205 201 194 195 193 195 192 186 57 38 72 65 57 62 58 57 60 54 49 47 79 116 130 138 141 141 139 141 143 145 157 164 164 166 173 174 176 179 179 176 181 189 188 173 180 175 160 182 189 198 192 189 190 190 188 172 46 44 64 66 59 62 57 56 62 53 50 66 103 133 137 141 143 141 136 132 131 136 127 118 111 107 108 123 131 143 154 158 166 177 181 175 170 159 148 171 161 176 185 192 194 188 190 162 53 49 58 63 61 61 55 56 61 51 50 81 116 139 142 142 146 144 136 128 119 112 97 85 90 91 88 92 90 80 81 84 106 122 132 144 145 144 147 163 147 163 173 181 190 187 191 167 61 48 53 61 61 58 54 56 61 51 53 89 123 140 144 145 146 147 136 122 107 99 95 92 90 87 83 76 67 52 46 52 63 69 83 96 119 132 148 159 136 137 143 138 143 152 156 156 70 48 50 59 61 57 54 54 61 52 56 93 124 135 140 144 148 150 140 125 114 101 80 54 56 54 41 41 33 40 39 35 49 60 63 74 107 129 147 147 116 111 100 77 76 86 108 111 73 49 50 60 62 60 57 55 63 59 56 89 121 134 139 146 151 152 150 141 127 111 96 77 85 70 32 31 37 91 65 50 48 59 73 83 112 136 155 130 60 46 38 40 43 81 116 91 72 52 48 58 62 62 59 53 61 59 52 85 114 134 140 147 154 159 158 153 145 143 150 126 121 125 68 45 89 137 95 70 78 75 95 109 131 153 171 94 23 16 32 82 82 65 113 77 71 54 48 56 62 62 60 53 60 56 52 75 108 133 141 149 158 166 169 167 163 156 155 146 112 119 134 127 142 140 121 117 129 114 120 129 146 174 191 98 46 33 33 109 147 98 109 67 73 55 50 56 64 64 61 58 61 53 54 64 106 129 140 148 159 169 175 176 174 165 159 156 145 120 115 124 127 131 133 141 147 142 141 147 161 182 202 154 114 96 100 158 158 153 123 61 76 57 48 56 64 64 63 62 61 54 55 44 97 131 137 147 158 168 177 181 183 179 170 168 169 165 155 152 151 152 154 162 165 158 153 158 168 187 206 186 147 135 144 145 152 178 115 57 74 58 48 58 64 63 63 59 63 55 53 66 104 130 132 144 153 162 170 180 185 187 181 178 182 180 177 173 171 171 177 176 172 164 161 167 164 185 207 197 173 152 141 141 161 191 104 54 69 60 48 57 65 62 60 57 64 55 50 94 111 124 130 135 150 159 163 172 179 184 184 178 178 177 173 171 174 177 178 176 169 165 161 163 161 180 205 201 183 171 177 178 180 194 101 55 65 60 47 55 65 63 59 58 63 57 52 90 105 117 122 130 143 153 157 163 171 174 182 183 182 178 174 175 175 177 175 172 163 161 159 157 162 178 200 201 188 181 172 177 187 198 98 57 63 61 48 52 61 64 63 60 65 57 51 95 104 113 117 127 136 145 152 156 162 162 165 173 177 182 183 183 180 181 177 165 153 154 152 153 160 174 193 200 188 185 180 182 192 196 101 60 60 56 49 50 60 66 64 62 64 59 53 99 104 111 112 118 132 142 147 155 158 160 159 162 171 176 184 186 183 180 169 154 141 135 145 155 164 180 196 205 188 189 188 189 193 192 98 61 64 55 49 49 60 66 63 64 63 60 57 99 105 108 112 113 125 139 143 150 155 158 164 169 174 176 182 183 182 177 163 141 133 147 151 164 170 185 200 210 194 188 192 186 185 180 88 64 67 60 46 50 59 65 64 64 64 59 56 101 103 108 109 109 118 134 143 143 147 155 159 166 171 174 177 179 178 172 153 129 143 161 159 166 171 186 197 207 203 185 191 183 179 164 73 67 67 66 48 50 57 65 65 63 64 61 57 103 108 114 112 110 115 128 138 144 145 152 156 159 164 168 172 172 169 161 139 125 147 156 161 162 164 180 188 188 197 185 187 181 180 137 65 70 68 70 52 47 53 62 65 63 65 61 58 105 109 112 120 113 112 122 134 141 149 150 153 155 159 164 167 167 162 152 134 115 126 119 106 99 109 141 158 150 155 175 184 176 175 106 63 70 68 68 50 46 50 57 63 63 64 61 59 107 110 110 117 117 114 117 128 137 147 148 150 153 156 161 162 163 156 150 148 105 70 45 26 25 47 73 74 79 128 177 180 173 157 77 66 68 67 68 52 49 51 56 62 62 62 62 60 101 107 108 114 115 114 117 125 134 143 148 149 152 154 158 160 158 155 160 158 132 88 73 73 64 52 66 91 138 160 174 173 171 125 64 67 63 64 68 54 50 49 54 60 60 60 62 60 98 105 105 109 111 114 117 125 131 139 145 148 153 153 156 157 156 161 168 165 153 139 122 115 105 89 103 150 182 161 171 173 162 89 64 64 62 64 69 56 48 49 56 58 60 59 62 60 89 99 108 106 109 111 119 120 125 134 140 146 152 153 153 153 156 159 162 160 150 136 129 133 133 122 133 148 178 168 168 175 132 61 67 66 65 63 69 57 47 50 55 58 59 61 62 60 89 96 105 107 105 107 117 120 123 124 133 141 149 153 151 145 151 145 139 140 138 128 126 124 129 125 136 142 164 172 168 168 87 58 67 63 62 61 69 57 39 44 55 56 59 63 62 62 84 91 92 98 102 103 113 119 121 118 128 138 146 151 147 142 140 128 127 128 129 126 135 140 135 130 143 146 149 166 174 131 62 65 62 59 67 63 68 83 89 65 42 52 60 60 62 63 77 84 84 91 99 101 107 112 117 118 122 134 145 149 144 134 127 127 129 130 134 125 126 132 152 153 151 150 151 165 171 87 59 65 64 61 58 86 122 138 208 207 154 71 52 56 55 56 69 77 83 85 93 91 102 112 116 118 119 127 140 144 142 131 112 95 85 75 62 58 56 59 87 88 83 127 142 165 149 62 65 62 59 77 113 192 156 84 185 196 197 168 81 70 75 69 58 65 73 82 81 79 95 107 114 116 116 123 136 142 136 132 131 102 71 58 49 41 33 41 36 49 60 99 136 168 111 53 63 71 138 186 203 195 146 87 91 72 79 95 103 82 61 74 55 57 68 75 76 77 84 96 106 110 111 121 130 138 136 142 153 159 152 152 154 145 133 136 147 158 156 155 147 158 74 57 60 123 181 174 126 89 72 67 57 43 55 67 76 86 60 45 51 45 52 68 75 73 77 88 96 100 104 113 115 121 134 146 149 146 149 148 155 168 174 179 178 169 169 174 161 131 44 47 82 150 168 136 104 75 66 80 67 58 48 54 68 88 121 102 51 45 38 53 66 65 70 86 92 96 102 103 109 116 130 136 136 133 136 138 137 135 128 130 143 158 165 164 147 87 62 74 123 160 170 100 99 107 79 71 86 75 57 45 49 65 122 130 43 48 40 39 55 61 59 71 82 87 88 93 105 118 123 128 130 124 111 98 94 88 67 55 84 129 147 148 105 48 82 142 161 164 164 76 72 85 100 88 72 90 84 54 48 54 73 100 73 36 44 31 37 53 51 55 67 74 77 87 97 108 118 125 132 122 106 86 80 82 75 73 83 110 129 126 46 22 130 177 196 193 166 72 52 54 73 100 92 75 99 95 65 68 61 63 91 65 42 37 22 28 39 44 57 68 74 83 92 101 119 131 143 141 134 136 140 139 134 136 139 138 136 85 23 114 202 198 199 180 173 98 36 86 130 150 137 99 77 101 99 72 56 43 77 82 79 70 56 28 20 25 36 50 63 73 83 98 111 124 139 156 160 159 169 168 165 163 159 149 114 43 26 133 183 192 177 152 137 130 125 139 173 195 186 137 101 88 101 105 70 46 77 72 84 87 87 81 64 37 20 31 40 46 65 88 108 110 125 149 157 153 162 164 158 159 154 140 78 21 11 61 144 168 173 157 138 150 148 132 159 182 183 136 106 116 95 106 109 82";
//save string as byte array
var arrrStr = img.Split(" ").Select(s => Convert.ToString(s)).ToArray();
var byt = arrrStr.Select(byte.Parse).ToArray();
//save the file by this array, the line below throws an exception.
using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(byt)))
{
image.Save("output.jpg", ImageFormat.Jpeg); // Or Png
}
And as you guess it doesn't work, how to convert this pixel string to file(this value is generated from a file in origin)

Finding Last Record Per Group with Multiple Aggregate Functions- SQLite

I have a table ("trds") that contains fields RefDate, Symbol, Timestamp, Sequence, Quantity, Price, SaleCondition, Pid, and Submkt ("select * from trds limit 100"):
RefDate Symbol Timestamp Sequence Quantity Price SaleCondition Pid SubMkt
1 2015-08-03 AAPL 14400002 507 10 121.50 # TI P
2 2015-08-03 AAPL 14400026 1017 100 121.39 T P
3 2015-08-03 AAPL 14400026 1018 520 121.39 T P
4 2015-08-03 AAPL 14400026 1019 100 121.40 T P
5 2015-08-03 AAPL 14400028 1020 100 121.49 T P
6 2015-08-03 AAPL 14400028 1021 2172 121.49 T P
7 2015-08-03 AAPL 14425890 1026 100 121.49 T P
8 2015-08-03 AAPL 14426989 1027 100 121.49 T P
9 2015-08-03 AAPL 14433658 1028 137 121.40 #FT P
10 2015-08-03 AAPL 14628998 1029 200 121.40 T P
11 2015-08-03 AAPL 14637576 1030 5328 121.40 # T P
12 2015-08-03 AAPL 14637576 1031 200 121.45 #FT Q
13 2015-08-03 AAPL 15116858 1032 3040 121.40 T P
14 2015-08-03 AAPL 15129926 1034 1295 121.40 T P
15 2015-08-03 AAPL 15130128 1035 201 121.30 T P
16 2015-08-03 AAPL 15237959 1036 126 121.30 T P
17 2015-08-03 AAPL 15553155 1043 20 121.03 # TI P
18 2015-08-03 AAPL 15646925 1044 80 121.03 # TI P
19 2015-08-03 AAPL 15844129 1050 40 121.22 #FTI Q
20 2015-08-03 AAPL 16908849 1055 190 121.22 #FT Q
21 2015-08-03 AAPL 16998884 1056 260 121.22 #FT Q
22 2015-08-03 AAPL 17682717 1057 10 121.22 #FTI Q
23 2015-08-03 AAPL 17682717 1058 190 121.23 #FT Q
24 2015-08-03 AAPL 17736566 1059 100 121.23 #FT Q
25 2015-08-03 AAPL 18102786 1061 100 121.22 #FT Q
26 2015-08-03 AAPL 18102786 1062 100 121.22 #FT Q
27 2015-08-03 AAPL 18103386 1063 700 121.23 #FT Q
28 2015-08-03 AAPL 19170799 1064 200 121.22 #FT P
29 2015-08-03 AAPL 19171001 1065 40 121.22 #FTI P
30 2015-08-03 AAPL 19557088 1068 500 121.21 T P
31 2015-08-03 AAPL 19995780 1072 50 121.00 #FTI P
32 2015-08-03 AAPL 19995780 1073 450 121.00 #FT P
33 2015-08-03 AAPL 20110219 1074 100 121.00 #FT P
34 2015-08-03 AAPL 20131347 1075 100 121.00 #FT P
35 2015-08-03 AAPL 20288087 1076 50 121.01 #FTI P
36 2015-08-03 AAPL 20288282 1077 250 121.00 #FT P
37 2015-08-03 AAPL 20776851 1081 200 121.22 T P
38 2015-08-03 AAPL 20777052 1082 300 121.22 T P
39 2015-08-03 AAPL 21416707 1084 200 121.22 T P
40 2015-08-03 AAPL 21416907 1085 300 121.22 T P
41 2015-08-03 AAPL 21740935 1086 200 121.22 #FT P
42 2015-08-03 AAPL 21741136 1087 33 121.22 #FTI P
43 2015-08-03 AAPL 22289290 1088 50 121.22 # TI P
44 2015-08-03 AAPL 22302889 1089 150 121.22 T P
45 2015-08-03 AAPL 22303093 1090 350 121.22 T P
46 2015-08-03 AAPL 22324450 1091 100 121.22 T P
47 2015-08-03 AAPL 22325298 1092 100 121.22 T P
48 2015-08-03 AAPL 22489509 1093 200 121.22 T P
49 2015-08-03 AAPL 22489711 1094 300 121.22 T P
50 2015-08-03 AAPL 22651416 1096 200 121.22 #FT P
51 2015-08-03 AAPL 22656656 1097 77 121.22 # TI P
52 2015-08-03 AAPL 22656857 1098 10 121.23 # TI P
53 2015-08-03 AAPL 22762084 1099 87 121.37 #FTI Q
54 2015-08-03 AAPL 22762084 1100 413 121.38 #FT Q
55 2015-08-03 AAPL 22956526 1103 20 121.20 # TI P
56 2015-08-03 AAPL 22956727 1104 180 121.18 T P
57 2015-08-03 AAPL 23254802 1105 36 121.27 # TI P
58 2015-08-03 AAPL 24077374 1110 144 121.27 T P
59 2015-08-03 AAPL 24077374 1111 50 121.29 # TI P
60 2015-08-03 AAPL 24077374 1112 306 121.30 T P
61 2015-08-03 AAPL 24121832 1113 2 121.30 # TI P
62 2015-08-03 AAPL 24164641 1116 1000 121.30 T P
63 2015-08-03 AAPL 24168414 1117 600 121.30 T P
64 2015-08-03 AAPL 24192881 1120 92 121.30 # TI P
65 2015-08-03 AAPL 24192882 1121 408 121.38 #FT Q
66 2015-08-03 AAPL 24331392 1122 400 121.45 # T P
67 2015-08-03 AAPL 24331392 1123 100 121.38 #FT Q
68 2015-08-03 AAPL 24336664 1124 79 121.38 # TI P
69 2015-08-03 AAPL 24464675 1125 1000 121.40 T P
70 2015-08-03 AAPL 24587817 1126 496 121.38 T P
71 2015-08-03 AAPL 24588021 1127 504 121.39 T P
72 2015-08-03 AAPL 24600057 1128 500 121.38 T P
73 2015-08-03 AAPL 24667891 1130 500 121.37 T P
74 2015-08-03 AAPL 24723357 1131 50 121.39 # TI P
75 2015-08-03 AAPL 24778654 1132 1000 121.39 T P
76 2015-08-03 AAPL 24908008 1133 200 121.39 T P
77 2015-08-03 AAPL 24908210 1134 300 121.40 T P
78 2015-08-03 AAPL 24912914 1135 1500 121.40 T P
79 2015-08-03 AAPL 25011487 1136 500 121.40 T P
80 2015-08-03 AAPL 25018982 1137 100 121.40 T P
81 2015-08-03 AAPL 25023375 1138 21 121.40 # TI P
82 2015-08-03 AAPL 25064872 1139 600 121.40 T P
83 2015-08-03 AAPL 25111247 1140 500 121.40 T P
84 2015-08-03 AAPL 25112575 1141 200 121.40 T P
85 2015-08-03 AAPL 25139881 1142 200 121.40 T P
86 2015-08-03 AAPL 25140659 1143 79 121.40 # TI P
87 2015-08-03 AAPL 25140869 1144 421 121.45 T P
88 2015-08-03 AAPL 25219916 1146 200 121.45 T P
89 2015-08-03 AAPL 25229789 1147 50 121.36 #FTI P
90 2015-08-03 AAPL 25229988 1148 29 121.35 #FTI P
91 2015-08-03 AAPL 25290394 1160 200 121.43 T P
92 2015-08-03 AAPL 25392283 1168 30 121.40 # TI P
93 2015-08-03 AAPL 25421012 1169 300 121.40 T P
94 2015-08-03 AAPL 25755052 1173 2 121.45 # TI P
95 2015-08-03 AAPL 25763189 1174 60 121.44 # TI P
96 2015-08-03 AAPL 25942067 1182 200 121.46 #FT P
97 2015-08-03 AAPL 25942068 1183 100 121.47 #FT P
98 2015-08-03 AAPL 25942068 1184 100 121.47 #FT P
99 2015-08-03 AAPL 25942070 1185 100 121.47 #FT P
100 2015-08-03 AAPL 25948942 1186 1000 121.48 T
I need to create a query that groups together all trades in five minute intervals and finds the Min/Max/Avg and Last Price of each group. "Timestamp" is milliseconds since midnight (so 9:30 is 34200000), and I only want to include between 9:30 and 4:00. I created timebucket by dividing by five minute intervals (300,000 ms): cast(timestamp/300e3) as int) as timebucket.
The end result should look like this:
I can produce code to get the Min/Max/Avg price that looks like this:
dbGetQuery(nqdb, statement = "select t.RefDate, t.Symbol, cast(t.Timestamp/300e3 as int) as timeBucket,
Min(time(t.timestamp/1000, 'unixepoch')) as startTime, Max(t.Price) as MaxPrice,
Min(t.Price) as MinPrice, Avg(t.Price) as AvgPrice
from trds t
where (t.Timestamp between 34200000 and 57600000) and
SaleCondition not glob '*[CGIHMNPQRTUVWZ47]*' group by timeBucket, symbol order by symbol ASC")
This is somewhat close, although the StartTime has seconds in the HH:MM:SS field when it shouldn't, and I've tried everything from sub-queries to sub-selects and searched through "greatest-n-per-group" forums to get the "LastPrice" to no avail. Here's the output:
RefDate Symbol timeBucket startTime MaxPrice MinPrice AvgPrice
1 2015-08-03 AAPL 114 09:30:00 121.5000 121.0500 121.22574
2 2015-08-03 AAPL 115 09:35:00 122.4700 121.2200 121.86515
3 2015-08-03 AAPL 116 09:40:00 122.5700 122.1000 122.37850
4 2015-08-03 AAPL 117 09:45:00 122.2000 121.8901 122.00520
5 2015-08-03 AAPL 118 09:50:00 122.2900 122.0000 122.10803
6 2015-08-03 AAPL 119 09:55:00 122.2100 121.7000 122.02053
7 2015-08-03 AAPL 120 10:00:00 121.8900 121.4100 121.73007
8 2015-08-03 AAPL 121 10:05:00 121.5500 121.2500 121.38513
9 2015-08-03 AAPL 122 10:10:00 121.6200 121.2550 121.48453
10 2015-08-03 AAPL 123 10:15:00 121.5200 121.2700 121.38975
11 2015-08-03 AAPL 124 10:20:00 121.3400 121.1500 121.25174
12 2015-08-03 AAPL 125 10:25:00 121.1600 120.7750 120.92567
13 2015-08-03 AAPL 126 10:30:00 121.0400 120.8100 120.90262
14 2015-08-03 AAPL 127 10:35:01 121.0000 120.7800 120.88182
15 2015-08-03 AAPL 128 10:40:00 121.0000 120.8600 120.91147
16 2015-08-03 AAPL 129 10:45:00 120.9083 120.7330 120.81935
17 2015-08-03 AAPL 130 10:50:00 120.8400 120.5500 120.71769
18 2015-08-03 AAPL 131 10:55:00 120.7200 120.5300 120.62324
19 2015-08-03 AAPL 132 11:00:00 120.8200 120.6500 120.71650
20 2015-08-03 AAPL 133 11:05:00 120.9900 120.6500 120.83935
21 2015-08-03 AAPL 134 11:10:00 121.1800 120.9100 121.02811
22 2015-08-03 AAPL 135 11:15:00 121.1700 120.9700 121.05849
23 2015-08-03 AAPL 136 11:20:01 121.1500 121.0480 121.09072
24 2015-08-03 AAPL 137 11:25:00 121.1500 120.9500 121.04811
25 2015-08-03 AAPL 138 11:30:00 121.1200 120.9200 121.02047
26 2015-08-03 AAPL 139 11:35:00 120.9900 120.6700 120.82496
27 2015-08-03 AAPL 140 11:40:00 120.8400 120.5600 120.68603
28 2015-08-03 AAPL 141 11:45:00 120.8600 120.6600 120.75718
29 2015-08-03 AAPL 142 11:50:00 120.6800 120.3300 120.46856
30 2015-08-03 AAPL 143 11:55:00 120.5155 120.4100 120.45356
31 2015-08-03 AAPL 144 12:00:00 120.5500 120.2200 120.32099
32 2015-08-03 AAPL 145 12:05:00 120.3000 120.1100 120.20832
33 2015-08-03 AAPL 146 12:10:00 120.1734 119.9000 120.02722
34 2015-08-03 AAPL 147 12:15:00 120.0600 119.8700 119.96583
35 2015-08-03 AAPL 148 12:20:00 119.9900 119.8100 119.89728
36 2015-08-03 AAPL 149 12:25:01 120.2200 119.8900 120.03213
37 2015-08-03 AAPL 150 12:30:00 120.1800 119.9200 120.03840
38 2015-08-03 AAPL 151 12:35:00 119.9756 119.7700 119.87204
39 2015-08-03 AAPL 152 12:40:00 119.9000 119.7500 119.82387
40 2015-08-03 AAPL 153 12:45:00 119.8353 118.7000 119.16163
41 2015-08-03 AAPL 154 12:50:00 118.9890 118.2600 118.66432
42 2015-08-03 AAPL 155 12:55:00 118.5000 117.5200 117.95536
43 2015-08-03 AAPL 156 13:00:00 118.4367 117.9500 118.15729
44 2015-08-03 AAPL 157 13:05:00 118.4500 117.7101 118.08337
45 2015-08-03 AAPL 158 13:10:00 118.1200 117.6700 117.87640
46 2015-08-03 AAPL 159 13:15:00 118.0100 117.6601 117.82184
47 2015-08-03 AAPL 160 13:20:00 118.1700 117.6100 117.98232
48 2015-08-03 AAPL 161 13:25:00 118.4400 118.0200 118.27480
49 2015-08-03 AAPL 162 13:30:00 118.4500 118.2000 118.33434
50 2015-08-03 AAPL 163 13:35:00 118.5500 118.3000 118.45115
51 2015-08-03 AAPL 164 13:40:00 118.6400 118.3200 118.50168
52 2015-08-03 AAPL 165 13:45:00 118.6800 118.4400 118.54192
53 2015-08-03 AAPL 166 13:50:00 118.8300 118.6000 118.74204
54 2015-08-03 AAPL 167 13:55:00 118.8400 118.6500 118.73936
55 2015-08-03 AAPL 168 14:00:00 118.7300 118.5200 118.60532
56 2015-08-03 AAPL 169 14:05:00 118.6500 118.4300 118.50543
57 2015-08-03 AAPL 170 14:10:00 118.5800 118.4300 118.49353
58 2015-08-03 AAPL 171 14:15:01 118.7100 118.4600 118.58022
59 2015-08-03 AAPL 172 14:20:00 118.5600 118.4000 118.48883
60 2015-08-03 AAPL 173 14:25:00 118.6500 118.3300 118.49131
61 2015-08-03 AAPL 174 14:30:00 118.6675 118.4900 118.56914
62 2015-08-03 AAPL 175 14:35:00 118.6500 118.4700 118.55887
63 2015-08-03 AAPL 176 14:40:00 118.8100 118.5600 118.69735
64 2015-08-03 AAPL 177 14:45:00 118.8000 118.6200 118.72279
65 2015-08-03 AAPL 178 14:50:00 118.7800 118.6200 118.71055
66 2015-08-03 AAPL 179 14:55:00 118.7500 118.5700 118.65656
67 2015-08-03 AAPL 180 15:00:00 118.8700 118.6500 118.72095
68 2015-08-03 AAPL 181 15:05:00 118.8700 118.6900 118.78130
69 2015-08-03 AAPL 182 15:10:00 118.7200 118.4600 118.61231
70 2015-08-03 AAPL 183 15:15:01 118.6000 118.3000 118.42988
71 2015-08-03 AAPL 184 15:20:03 118.4000 118.0700 118.23301
72 2015-08-03 AAPL 185 15:25:00 118.1000 117.8600 117.99564
73 2015-08-03 AAPL 186 15:30:00 118.1900 117.9600 118.08736
74 2015-08-03 AAPL 187 15:35:00 118.1700 117.8800 117.99449
75 2015-08-03 AAPL 188 15:40:00 118.2700 118.1000 118.16962
76 2015-08-03 AAPL 189 15:45:00 118.2000 117.9600 118.08088
77 2015-08-03 AAPL 190 15:50:00 118.1700 118.0000 118.07813
78 2015-08-03 AAPL 191 15:55:00 118.4500 118.0300 118.23987
79 2015-08-03 AMZN 114 09:30:00 538.5500 536.3200 537.61255
80 2015-08-03 AMZN 115 09:35:04 537.4600 535.7700 536.42177
81 2015-08-03 AMZN 116 09:40:01 538.3500 536.4000 537.68861
82 2015-08-03 AMZN 117 09:45:00 539.3500 536.2800 537.56732
83 2015-08-03 AMZN 118 09:50:00 539.9500 538.7100 539.45455
84 2015-08-03 AMZN 119 09:55:03 540.4400 538.8100 539.66087
85 2015-08-03 AMZN 120 10:00:00 540.2600 537.7100 539.01779
86 2015-08-03 AMZN 121 10:05:00 538.4050 536.5500 537.48823
87 2015-08-03 AMZN 122 10:10:03 537.6800 536.8000 537.21956
88 2015-08-03 AMZN 123 10:15:00 536.8000 534.1500 535.24578
89 2015-08-03 AMZN 124 10:20:01 535.0500 533.7700 534.51831
90 2015-08-03 AMZN 125 10:25:04 535.3900 534.1200 534.74367
91 2015-08-03 AMZN 126 10:30:13 534.9700 534.0110 534.64140
92 2015-08-03 AMZN 127 10:35:04 535.3500 534.5001 534.92485
93 2015-08-03 AMZN 128 10:40:04 535.1600 534.1000 534.57402
94 2015-08-03 AMZN 129 10:45:02 536.0000 534.5100 535.26481
95 2015-08-03 AMZN 130 10:50:00 536.3500 535.4500 535.93280
96 2015-08-03 AMZN 131 10:55:02 536.6500 535.2600 535.96416
97 2015-08-03 AMZN 132 11:00:01 536.6000 535.6800 536.24564
98 2015-08-03 AMZN 133 11:05:10 537.8900 536.4800 537.23168
99 2015-08-03 AMZN 134 11:10:00 538.5200 537.3500 537.94708
100 2015-08-03 AMZN 135 11:15:02 537.9400 537.3500 537.58755
101 2015-08-03 AMZN 136 11:20:05 537.9050 536.8600 537.31598
I'm guessing there's a more elegant solution than the Min(time) work around I used. But the primary question is how to find the LastPrice in each five minute interval?
Update- This is a separate query I did that produces the last price per five minute group, but without Min(Price), Max(Price), and Avg(Price). I do not know how to combine all of them in one query.
dbGetQuery(nqdb, statement = "select t.RefDate, t.Symbol, cast(t.Timestamp/300e3 as int) as timeBucket,
time(t.timestamp/1000, 'unixepoch') as startTime,
t.price as LastPrice from trds t
where (t.Timestamp between 34200000 and 57600000) and
SaleCondition not glob '*[CGIHMNPQRTUVWZ47]*' group by timeBucket, symbol order by symbol ASC")
RefDate Symbol timeBucket startTime LastPrice
1 2015-08-03 AAPL 114 09:34:00 121.2300
2 2015-08-03 AAPL 115 09:39:00 122.4400
3 2015-08-03 AAPL 116 09:44:00 122.1800
4 2015-08-03 AAPL 117 09:49:00 122.0500
5 2015-08-03 AAPL 118 09:54:00 122.0700
6 2015-08-03 AAPL 119 09:59:00 121.7700
7 2015-08-03 AAPL 120 10:04:00 121.5400
8 2015-08-03 AAPL 121 10:09:00 121.2600
9 2015-08-03 AAPL 122 10:14:00 121.5140
10 2015-08-03 AAPL 123 10:19:00 121.2700
11 2015-08-03 AAPL 124 10:24:00 121.1600
12 2015-08-03 AAPL 125 10:29:00 121.0200
13 2015-08-03 AAPL 126 10:34:00 120.9200
14 2015-08-03 AAPL 127 10:39:00 120.9900
15 2015-08-03 AAPL 128 10:44:00 120.8600
16 2015-08-03 AAPL 129 10:49:00 120.7800
17 2015-08-03 AAPL 130 10:54:00 120.6200
18 2015-08-03 AAPL 131 10:59:00 120.6500
19 2015-08-03 AAPL 132 11:04:00 120.6900
20 2015-08-03 AAPL 133 11:09:00 120.9600
21 2015-08-03 AAPL 134 11:14:00 121.0237
22 2015-08-03 AAPL 135 11:19:00 121.0899
23 2015-08-03 AAPL 136 11:24:00 121.1010
24 2015-08-03 AAPL 137 11:29:00 120.9954
25 2015-08-03 AAPL 138 11:34:00 120.9895
26 2015-08-03 AAPL 139 11:39:00 120.6750
27 2015-08-03 AAPL 140 11:44:00 120.8200
28 2015-08-03 AAPL 141 11:49:00 120.6750
29 2015-08-03 AAPL 142 11:54:00 120.4500
30 2015-08-03 AAPL 143 11:59:00 120.4900
31 2015-08-03 AAPL 144 12:04:00 120.2449
32 2015-08-03 AAPL 145 12:09:00 120.1600
33 2015-08-03 AAPL 146 12:14:00 120.0200
34 2015-08-03 AAPL 147 12:19:00 119.8700
35 2015-08-03 AAPL 148 12:24:00 119.9400
36 2015-08-03 AAPL 149 12:29:00 120.1770
37 2015-08-03 AAPL 150 12:34:00 119.9505
38 2015-08-03 AAPL 151 12:39:00 119.8400
39 2015-08-03 AAPL 152 12:44:00 119.8400
40 2015-08-03 AAPL 153 12:49:00 118.9400
41 2015-08-03 AAPL 154 12:54:00 118.4900
42 2015-08-03 AAPL 155 12:59:00 118.0000
43 2015-08-03 AAPL 156 13:04:00 118.4300
44 2015-08-03 AAPL 157 13:09:00 117.7286
45 2015-08-03 AAPL 158 13:14:00 117.9173
46 2015-08-03 AAPL 159 13:19:00 117.6700
47 2015-08-03 AAPL 160 13:24:00 118.1200
48 2015-08-03 AAPL 161 13:29:00 118.3601
49 2015-08-03 AAPL 162 13:34:00 118.4400
50 2015-08-03 AAPL 163 13:39:00 118.3000
Update: per #Parfait-on the timestamp issue, it mostly works, however one of the the output is off with one Symbol. Also still doesn't solve the problem of finding the Last Price per five minute group along with min/max/avg:
157 2015-08-03 DAVE 114 09:30:00 17.9600 17.9300 17.94500
158 2015-08-03 DAVE 115 09:37:00 17.9994 17.9100 17.95470
159 2015-08-03 DAVE 116 09:40:00 17.8700 17.8700 17.87000
160 2015-08-03 DAVE 118 09:50:00 17.7350 17.6950 17.71500
161 2015-08-03 DAVE 120 10:04:00 17.6900 17.6700 17.68000
162 2015-08-03 DAVE 121 10:08:00 17.5600 17.5600 17.56000
163 2015-08-03 DAVE 122 10:14:00 17.5600 17.5600 17.56000
164 2015-08-03 DAVE 124 10:24:00 17.6500 17.6500 17.65000
165 2015-08-03 DAVE 126 10:30:00 17.6000 17.5200 17.56000
166 2015-08-03 DAVE 127 10:39:00 17.4800 17.4800 17.48000
167 2015-08-03 DAVE 128 10:40:00 17.6100 17.4900 17.55000
168 2015-08-03 DAVE 129 10:47:00 17.4400 17.4400 17.44000
169 2015-08-03 DAVE 130 10:54:00 17.5600 17.5600 17.56000
170 2015-08-03 DAVE 131 10:55:00 17.4300 17.3800 17.40500
171 2015-08-03 DAVE 132 11:00:00 17.3400 17.2620 17.30720
172 2015-08-03 DAVE 133 11:09:00 17.2800 17.2700 17.27500
173 2015-08-03 DAVE 135 11:17:00 17.2700 17.2300 17.25000
174 2015-08-03 DAVE 136 11:23:00 17.3200 17.3000 17.31000
175 2015-08-03 DAVE 137 11:25:00 17.4000 17.3750 17.38875
176 2015-08-03 DAVE 139 11:39:00 17.4400 17.4400 17.44000
177 2015-08-03 DAVE 141 11:49:00 17.4200 17.4200 17.42000
178 2015-08-03 DAVE 142 11:51:00 17.4200 17.4200 17.42000
179 2015-08-03 DAVE 143 11:59:00 17.3900 17.3900 17.39000
180 2015-08-03 DAVE 144 12:01:00 17.4350 17.3600 17.39750
181 2015-08-03 DAVE 146 12:13:00 17.3700 17.3600 17.36500
182 2015-08-03 DAVE 147 12:17:00 17.3600 17.3500 17.35333
183 2015-08-03 DAVE 148 12:20:00 17.4000 17.3700 17.38500
184 2015-08-03 DAVE 149 12:25:00 17.3700 17.3700 17.37000
185 2015-08-03 DAVE 150 12:31:00 17.3300 17.3300 17.33000
186 2015-08-03 DAVE 153 12:49:00 17.3800 17.3800 17.38000
187 2015-08-03 DAVE 154 12:50:00 17.3900 17.3900 17.39000
188 2015-08-03 DAVE 155 12:55:00 17.3300 17.3300 17.33000
189 2015-08-03 DAVE 158 13:12:00 17.3400 17.3100 17.32500
190 2015-08-03 DAVE 159 13:15:00 17.3600 17.3400 17.35000
191 2015-08-03 DAVE 160 13:22:00 17.3700 17.3700 17.37000
192 2015-08-03 DAVE 162 13:34:00 17.3504 17.3504 17.35040
193 2015-08-03 DAVE 163 13:35:00 17.3300 17.3100 17.32000
194 2015-08-03 DAVE 165 13:49:00 17.3200 17.3200 17.32000
195 2015-08-03 DAVE 171 14:15:00 17.3500 17.2700 17.31563
196 2015-08-03 DAVE 172 14:20:00 17.4000 17.3500 17.36667
197 2015-08-03 DAVE 175 14:37:00 17.3900 17.3900 17.39000
198 2015-08-03 DAVE 176 14:40:00 17.4000 17.3500 17.37125
199 2015-08-03 DAVE 177 14:45:00 17.4100 17.3500 17.38300
200 2015-08-03 DAVE 178 14:51:00 17.4500 17.4500 17.45000
201 2015-08-03 DAVE 181 15:05:00 17.5800 17.5300 17.55700
202 2015-08-03 DAVE 182 15:10:00 17.5600 17.5200 17.54223
203 2015-08-03 DAVE 184 15:23:00 17.6900 17.6200 17.65500
204 2015-08-03 DAVE 186 15:30:00 17.6900 17.6900 17.69000
205 2015-08-03 DAVE 189 15:46:00 17.7500 17.7200 17.74000
Here's the time in seconds for the problem Symbol "DAVE":
RefDate Symbol timeBucket startTime MaxPrice MinPrice AvgPrice
1 2015-08-03 DAVE 114 34200708 17.9600 17.9300 17.94500
2 2015-08-03 DAVE 115 34628936 17.9994 17.9100 17.95470
3 2015-08-03 DAVE 116 34807939 17.8700 17.8700 17.87000
4 2015-08-03 DAVE 118 35415342 17.7350 17.6950 17.71500
5 2015-08-03 DAVE 120 36250083 17.6900 17.6700 17.68000
6 2015-08-03 DAVE 121 36528404 17.5600 17.5600 17.56000
7 2015-08-03 DAVE 122 36850085 17.5600 17.5600 17.56000
8 2015-08-03 DAVE 124 37450198 17.6500 17.6500 17.65000
9 2015-08-03 DAVE 126 37892189 17.6000 17.5200 17.56000
10 2015-08-03 DAVE 127 38389126 17.4800 17.4800 17.48000
11 2015-08-03 DAVE 128 38400053 17.6100 17.4900 17.55000
12 2015-08-03 DAVE 129 38861146 17.4400 17.4400 17.44000
13 2015-08-03 DAVE 130 39250319 17.5600 17.5600 17.56000
14 2015-08-03 DAVE 131 39301007 17.4300 17.3800 17.40500
15 2015-08-03 DAVE 132 39704588 17.3400 17.2620 17.30720
16 2015-08-03 DAVE 133 40150085 17.2800 17.2700 17.27500
17 2015-08-03 DAVE 135 40668185 17.2700 17.2300 17.25000
18 2015-08-03 DAVE 136 41026622 17.3200 17.3000 17.31000
19 2015-08-03 DAVE 137 41125827 17.4000 17.3750 17.38875
20 2015-08-03 DAVE 139 41950078 17.4400 17.4400 17.44000
21 2015-08-03 DAVE 141 42550193 17.4200 17.4200 17.42000
22 2015-08-03 DAVE 142 42704053 17.4200 17.4200 17.42000
23 2015-08-03 DAVE 143 43150086 17.3900 17.3900 17.39000
24 2015-08-03 DAVE 144 43439310 17.4350 17.3600 17.39750
25 2015-08-03 DAVE 146 44086864 17.3700 17.3600 17.36500
26 2015-08-03 DAVE 147 44250485 17.3600 17.3500 17.35333
27 2015-08-03 DAVE 148 44416744 17.4000 17.3700 17.38500
28 2015-08-03 DAVE 149 44748677 17.3700 17.3700 17.37000
29 2015-08-03 DAVE 150 45087379 17.3300 17.3300 17.33000
30 2015-08-03 DAVE 153 46149940 17.3800 17.3800 17.38000
31 2015-08-03 DAVE 154 46236704 17.3900 17.3900 17.39000
32 2015-08-03 DAVE 155 46513141 17.3300 17.3300 17.33000
33 2015-08-03 DAVE 158 47589401 17.3400 17.3100 17.32500
34 2015-08-03 DAVE 159 47706529 17.3600 17.3400 17.35000
35 2015-08-03 DAVE 160 48134567 17.3700 17.3700 17.37000
36 2015-08-03 DAVE 162 48856648 17.3504 17.3504 17.35040
37 2015-08-03 DAVE 163 48943090 17.3300 17.3100 17.32000
38 2015-08-03 DAVE 165 49755204 17.3200 17.3200 17.32000
39 2015-08-03 DAVE 171 51379248 17.3500 17.2700 17.31563
40 2015-08-03 DAVE 172 51622647 17.4000 17.3500 17.36667
41 2015-08-03 DAVE 175 52636324 17.3900 17.3900 17.39000
42 2015-08-03 DAVE 176 52921459 17.4000 17.3500 17.37125
43 2015-08-03 DAVE 177 53132520 17.4100 17.3500 17.38300
44 2015-08-03 DAVE 178 53516691 17.4500 17.4500 17.45000
45 2015-08-03 DAVE 181 54350810 17.5800 17.5300 17.55700
46 2015-08-03 DAVE 182 54749749 17.5600 17.5200 17.54223
47 2015-08-03 DAVE 184 55476188 17.6900 17.6200 17.65500
48 2015-08-03 DAVE 186 55804762 17.6900 17.6900 17.69000
49 2015-08-03 DAVE 189 56789594 17.7500 17.7200 17.74000
50 2015-08-03 DAVE 190 57274050 17.7800 17.6600 17.73333
51 2015-08-03 DAVE 191 57557752 17.7000 17.6300 17.66265
Consider subtracting its remainder using modulo operator, %, for nearest minute (i.e., 60 seconds):
Min(time(t.timestamp/1000 - (t.timestamp/1000) % 60, 'unixepoch')) as startTime
Also, to find first or last price run multiple aggregations using timestamp then left join the aggregates to a main query. Below uses CTE which should be available with latest SQLite version. Wrap entire query in an R string and it should return the last SELECT resultset as data frame.
Below uses a new five_min_grp and runs a self join of aggregate query but joined on different time stamps with the main unit level query.
with unit as
(select t.RefDate, t.Symbol, cast(t.Timestamp/300e3 as int) as timeBucket,
time(t.timestamp/1000 - (t.timestamp/1000) % 300, 'unixepoch') as five_min_grp,
time(t.timestamp/1000 - (t.timestamp/1000) % 60, 'unixepoch') as startTime,
t.price as Price
from trds t
where (t.Timestamp between 34200000 and 57600000)
and (t.SaleCondition not glob '*[CGIHMNPQRTUVWZ47]*')
),
agg as
(select u.RefDate, u.Symbol, u.five_min_grp,
min(u.startTime) as first_startTime,
max(u.startTime) as last_startTime
from unit u
group by u.RefDate, u.Symbol, u.five_min_grp
),
select u.RefDate, u.Symbol, u.five_min_grp,
avg(u.price) as AvgPrice,
min(u.price) as MinPrice,
max(u.price) as MaxPrice,
min(case when first.first_startTime is not null
then u.price
else null
end) as FirstPrice,
max(case when last.last_startTime is not null
then u.price
else null
end) as LastPrice
from unit u
left join agg first
on first.RefDate = u.RefDate
and first.Symbol = u.Symbol
and first.five_min_grp = u.five_min_grp
and first.first_startTime = u.startTime
left join agg last
on last.RefDate = u.RefDate
and last.Symbol = u.Symbol
and last.five_min_grp = u.five_min_grp
and last.last_startTime = u.startTime
group by u.RefDate, u.Symbol, u.five_min_grp
order by u.symbol
DB Fiddle Demo - does not use CTEs since its SQLite version is dated

Sorting a string of numbers into a grid

I'm needing to sort a long list of ID numbers into 'grids' of 8 ID numbers down (8 cells/rows), 6 ID numbers across (or 6 columns long etc), sorted from smallest to largest ID number. When one 'grid' is 'full', the numbers which cannot fit in the first grid should go on to form a second one and so on. The last 4 cells of the last row should be blank. (This is a template for a lab procedure).
ie this is the data I have:
column of ID numbers
and this how I want it to be (but like, 6 of these)
example 'grid'
Here's one method.
Sample data
import pandas as pd
import numpy as np
# Sorted list of string IDs
l = np.arange(0, 631, 1).astype('str')
Code
N = 44
# Ensure we can reshape last group
data = np.concatenate((l, np.repeat('', N-len(l)%N)))
# Split array, make a separate `DataFrame` for each grid.
data = [
pd.DataFrame(np.concatenate((x, np.repeat('', 4))).reshape(8,6))
for x in np.array_split(data, np.arange(N, len(l), N))
]
df = pd.concat(data, ignore_index=True) # If want a single df in the end
Output df:
0 1 2 3 4 5
0 0 1 2 3 4 5
1 6 7 8 9 10 11
2 12 13 14 15 16 17
3 18 19 20 21 22 23
4 24 25 26 27 28 29
5 30 31 32 33 34 35
6 36 37 38 39 40 41
7 42 43
8 44 45 46 47 48 49
9 50 51 52 53 54 55
10 56 57 58 59 60 61
11 62 63 64 65 66 67
12 68 69 70 71 72 73
13 74 75 76 77 78 79
14 80 81 82 83 84 85
15 86 87
16 88 89 90 91 92 93
...
110 608 609 610 611 612 613
111 614 615
112 616 617 618 619 620 621
113 622 623 624 625 626 627
114 628 629 630
115
116
117
118
119
func = lambda lst,n: np.pad(lst, (0,n*(1+len(lst)//n) - len(lst)), 'constant')
rows, cols = 8, 6
arr = np.arange(1, 283, 1) ##np.array(df.A)
new_df = pd.DataFrame(func(arr, rows*cols).reshape(-1,cols))
new_df
0 1 2 3 4 5
0 1 2 3 4 5 6
1 7 8 9 10 11 12
2 13 14 15 16 17 18
3 19 20 21 22 23 24
4 25 26 27 28 29 30
5 31 32 33 34 35 36
6 37 38 39 40 41 42
7 43 44 45 46 47 48
8 49 50 51 52 53 54
9 55 56 57 58 59 60
10 61 62 63 64 65 66
11 67 68 69 70 71 72
12 73 74 75 76 77 78
13 79 80 81 82 83 84
14 85 86 87 88 89 90
15 91 92 93 94 95 96
16 97 98 99 100 101 102
17 103 104 105 106 107 108
18 109 110 111 112 113 114
19 115 116 117 118 119 120
20 121 122 123 124 125 126
21 127 128 129 130 131 132
22 133 134 135 136 137 138
23 139 140 141 142 143 144
24 145 146 147 148 149 150
25 151 152 153 154 155 156
26 157 158 159 160 161 162
27 163 164 165 166 167 168
28 169 170 171 172 173 174
29 175 176 177 178 179 180
30 181 182 183 184 185 186
31 187 188 189 190 191 192
32 193 194 195 196 197 198
33 199 200 201 202 203 204
34 205 206 207 208 209 210
35 211 212 213 214 215 216
36 217 218 219 220 221 222
37 223 224 225 226 227 228
38 229 230 231 232 233 234
39 235 236 237 238 239 240
40 241 242 243 244 245 246
41 247 248 249 250 251 252
42 253 254 255 256 257 258
43 259 260 261 262 263 264
44 265 266 267 268 269 270
45 271 272 273 274 275 276
46 277 278 279 280 281 282
47 0 0 0 0 0 0
I think it's better to save this dataframe into an excel worksheet and then remove the last padded zeros manually. Hope this helped

Boto's multipart upload API is not working in AWS eu-central-1 region

I am trying to use boto's multipart upload API in my application. But it is failing with
The request signature we calculated does not match the signature you
provided. Check your key and signing method
Here are the error details
import boto
import boto3
s3_conn = boto.s3.connect_to_region('eu-central-1', aws_access_key_id=******, aws_secret_access_key=*****)
buckt = s3_conn.get_bucket('phoenix-4-147757042135')
mpuid = buckt.initiate_multipart_upload('4/5137/data_6000C298-a994-efe2-7e3b-efb3fd5a6c76/FULL/amar')
mpuid.copy_part_from_key('phoenix-4-147757042135', '4/5137/data_6000C298-a994-efe2-7e3b-efb3fd5a6c76/FULL/10000000', 1, 0, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/boto-2.39.0-py2.6.egg/boto/s3/multipart.py", line 306, in copy_part_from_key
query_args=query_args)
File "/usr/lib/python2.6/site-packages/boto-2.39.0-py2.6.egg/boto/s3/bucket.py", line 889, in copy_key
response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>ASIAIZZPTQJ3AWY3WG2Q</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA256
20161110T051801Z
20161110/eu-central-1/s3/aws4_request
bb44a9b3366ce1702d2850188d998eab092746bea906b50481ffe814137efde9</StringToSign><SignatureProvided>2d8b63e0c6f29d602e34ab426bf5704fcaaf6ae15c19550f047931a1da351211</SignatureProvided><StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 36 31 31 31 30 54 30 35 31 38 30 31 5a 0a 32 30 31 36 31 31 31 30 2f 65 75 2d 63 65 6e 74 72 61 6c 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 62 62 34 34 61 39 62 33 33 36 36 63 65 31 37 30 32 64 32 38 35 30 31 38 38 64 39 39 38 65 61 62 30 39 32 37 34 36 62 65 61 39 30 36 62 35 30 34 38 31 66 66 65 38 31 34 31 33 37 65 66 64 65 39</StringToSignBytes><CanonicalRequest>PUT
/4/5137/data_6000C298-a994-efe2-7e3b-efb3fd5a6c76/FULL/amar
partNumber=1&uploadId=PMd350jeac8vLRuC7qf9CEBckNBqXGWdaEL32a.bCw3Zet.K1IInwYmDEEnkU98.xHSnlucJLeis49yMg2M.NoyOdwAVU8VMYcve6Sv5ExJ8Yh9pc7UJrxli5O2p6PqxH83.I_pcIGttaybTT0ul2nwc79DOUSIpKO8TlMosfNI-
host:phoenix-4-147757042135.s3.eu-central-1.amazonaws.com
user-agent:Boto/2.39.0 Python/2.6.6 Linux/2.6.32-431.20.3.el6.x86_64
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-copy-source:phoenix-4-147757042135/4/5137/data_6000C298-a994-efe2-7e3b-efb3fd5a6c76/FULL/10000000
x-amz-copy-source-range:bytes=0-1
x-amz-date:20161110T051801Z
x-amz-security-token:FQoDYXdzEFYaDOR7x87//+eMX2hqwyK9A6+FKe1SX8gN2bpcbRJPuJxLZC+zP62TnzqoXA1lPvdKhjWpJI0v0UZ46Y+IcvbflIQXq438R8kC5QHJZHLx/fsDC7lPYLuDPA3d43V+cc28cn44pjD34DQpy0RKGMc7GJljZR+ijOb3m8e6bxv4c4kN83Kv+Gs7UBBa5EoGeg4NHN3neNN8g2u68Ad0uouPDV1Wvuiijbfp6ZIaT4LZFbq3mE11ZXiBjQDSDTDcLpO+ek3VCck6bpzquT/jDc8Jzrm6/rS8Giqs/xWLiATa4VqxVXzvbQ2Pu4Tv0kfCU7uc6DWMrBMhejj97s/HKLU0b12mcQ65T+FcieYALPfM4qPf27ZZVsjXWkCzkrMu8qOAblqpVCG15A2snZn0Ke6T7JF6ONGKkr1jSQ3Tv93C5/j6HuQOIcsuRKDLkBLgffOAyIzDzY2xBQvBIABTk0ENcLkgYzNLKsWLFuI3Pry24qcXVCSzXruyEE2neqZp8ohAvVh0WPZOtxmPOTbGgqRn2xEgb3yODAyz7+KOemRvfyGgxBGmvvSnuLrr24vY/6Inm49Q736eT7d5xmzflbLG6cdtBejyKmgttcOpuiEo9f2PwQU=
host;user-agent;x-amz-content-sha256;x-amz-copy-source;x-amz-copy-source-range;x-amz-date;x-amz-security-token
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855</CanonicalRequest><CanonicalRequestBytes>50 55 54 0a 2f 34 2f 35 31 33 37 2f 64 61 74 61 5f 36 30 30 30 43 32 39 38 2d 61 39 39 34 2d 65 66 65 32 2d 37 65 33 62 2d 65 66 62 33 66 64 35 61 36 63 37 36 2f 46 55 4c 4c 2f 61 6d 61 72 0a 70 61 72 74 4e 75 6d 62 65 72 3d 31 26 75 70 6c 6f 61 64 49 64 3d 50 4d 64 33 35 30 6a 65 61 63 38 76 4c 52 75 43 37 71 66 39 43 45 42 63 6b 4e 42 71 58 47 57 64 61 45 4c 33 32 61 2e 62 43 77 33 5a 65 74 2e 4b 31 49 49 6e 77 59 6d 44 45 45 6e 6b 55 39 38 2e 78 48 53 6e 6c 75 63 4a 4c 65 69 73 34 39 79 4d 67 32 4d 2e 4e 6f 79 4f 64 77 41 56 55 38 56 4d 59 63 76 65 36 53 76 35 45 78 4a 38 59 68 39 70 63 37 55 4a 72 78 6c 69 35 4f 32 70 36 50 71 78 48 38 33 2e 49 5f 70 63 49 47 74 74 61 79 62 54 54 30 75 6c 32 6e 77 63 37 39 44 4f 55 53 49 70 4b 4f 38 54 6c 4d 6f 73 66 4e 49 2d 0a 68 6f 73 74 3a 70 68 6f 65 6e 69 78 2d 34 2d 31 34 37 37 35 37 30 34 32 31 33 35 2e 73 33 2e 65 75 2d 63 65 6e 74 72 61 6c 2d 31 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 75 73 65 72 2d 61 67 65 6e 74 3a 42 6f 74 6f 2f 32 2e 33 39 2e 30 20 50 79 74 68 6f 6e 2f 32 2e 36 2e 36 20 4c 69 6e 75 78 2f 32 2e 36 2e 33 32 2d 34 33 31 2e 32 30 2e 33 2e 65 6c 36 2e 78 38 36 5f 36 34 0a 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3a 65 33 62 30 63 34 34 32 39 38 66 63 31 63 31 34 39 61 66 62 66 34 63 38 39 39 36 66 62 39 32 34 32 37 61 65 34 31 65 34 36 34 39 62 39 33 34 63 61 34 39 35 39 39 31 62 37 38 35 32 62 38 35 35 0a 78 2d 61 6d 7a 2d 63 6f 70 79 2d 73 6f 75 72 63 65 3a 70 68 6f 65 6e 69 78 2d 34 2d 31 34 37 37 35 37 30 34 32 31 33 35 2f 34 2f 35 31 33 37 2f 64 61 74 61 5f 36 30 30 30 43 32 39 38 2d 61 39 39 34 2d 65 66 65 32 2d 37 65 33 62 2d 65 66 62 33 66 64 35 61 36 63 37 36 2f 46 55 4c 4c 2f 31 30 30 30 30 30 30 30 0a 78 2d 61 6d 7a 2d 63 6f 70 79 2d 73 6f 75 72 63 65 2d 72 61 6e 67 65 3a 62 79 74 65 73 3d 30 2d 31 0a 78 2d 61 6d 7a 2d 64 61 74 65 3a 32 30 31 36 31 31 31 30 54 30 35 31 38 30 31 5a 0a 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 79 2d 74 6f 6b 65 6e 3a 46 51 6f 44 59 58 64 7a 45 46 59 61 44 4f 52 37 78 38 37 2f 2f 2b 65 4d 58 32 68 71 77 79 4b 39 41 36 2b 46 4b 65 31 53 58 38 67 4e 32 62 70 63 62 52 4a 50 75 4a 78 4c 5a 43 2b 7a 50 36 32 54 6e 7a 71 6f 58 41 31 6c 50 76 64 4b 68 6a 57 70 4a 49 30 76 30 55 5a 34 36 59 2b 49 63 76 62 66 6c 49 51 58 71 34 33 38 52 38 6b 43 35 51 48 4a 5a 48 4c 78 2f 66 73 44 43 37 6c 50 59 4c 75 44 50 41 33 64 34 33 56 2b 63 63 32 38 63 6e 34 34 70 6a 44 33 34 44 51 70 79 30 52 4b 47 4d 63 37 47 4a 6c 6a 5a 52 2b 69 6a 4f 62 33 6d 38 65 36 62 78 76 34 63 34 6b 4e 38 33 4b 76 2b 47 73 37 55 42 42 61 35 45 6f 47 65 67 34 4e 48 4e 33 6e 65 4e 4e 38 67 32 75 36 38 41 64 30 75 6f 75 50 44 56 31 57 76 75 69 69 6a 62 66 70 36 5a 49 61 54 34 4c 5a 46 62 71 33 6d 45 31 31 5a 58 69 42 6a 51 44 53 44 54 44 63 4c 70 4f 2b 65 6b 33 56 43 63 6b 36 62 70 7a 71 75 54 2f 6a 44 63 38 4a 7a 72 6d 36 2f 72 53 38 47 69 71 73 2f 78 57 4c 69 41 54 61 34 56 71 78 56 58 7a 76 62 51 32 50 75 34 54 76 30 6b 66 43 55 37 75 63 36 44 57 4d 72 42 4d 68 65 6a 6a 39 37 73 2f 48 4b 4c 55 30 62 31 32 6d 63 51 36 35 54 2b 46 63 69 65 59 41 4c 50 66 4d 34 71 50 66 32 37 5a 5a 56 73 6a 58 57 6b 43 7a 6b 72 4d 75 38 71 4f 41 62 6c 71 70 56 43 47 31 35 41 32 73 6e 5a 6e 30 4b 65 36 54 37 4a 46 36 4f 4e 47 4b 6b 72 31 6a 53 51 33 54 76 39 33 43 35 2f 6a 36 48 75 51 4f 49 63 73 75 52 4b 44 4c 6b 42 4c 67 66 66 4f 41 79 49 7a 44 7a 59 32 78 42 51 76 42 49 41 42 54 6b 30 45 4e 63 4c 6b 67 59 7a 4e 4c 4b 73 57 4c 46 75 49 33 50 72 79 32 34 71 63 58 56 43 53 7a 58 72 75 79 45 45 32 6e 65 71 5a 70 38 6f 68 41 76 56 68 30 57 50 5a 4f 74 78 6d 50 4f 54 62 47 67 71 52 6e 32 78 45 67 62 33 79 4f 44 41 79 7a 37 2b 4b 4f 65 6d 52 76 66 79 47 67 78 42 47 6d 76 76 53 6e 75 4c 72 72 32 34 76 59 2f 36 49 6e 6d 34 39 51 37 33 36 65 54 37 64 35 78 6d 7a 66 6c 62 4c 47 36 63 64 74 42 65 6a 79 4b 6d 67 74 74 63 4f 70 75 69 45 6f 39 66 32 50 77 51 55 3d 0a 0a 68 6f 73 74 3b 75 73 65 72 2d 61 67 65 6e 74 3b 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3b 78 2d 61 6d 7a 2d 63 6f 70 79 2d 73 6f 75 72 63 65 3b 78 2d 61 6d 7a 2d 63 6f 70 79 2d 73 6f 75 72 63 65 2d 72 61 6e 67 65 3b 78 2d 61 6d 7a 2d 64 61 74 65 3b 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 79 2d 74 6f 6b 65 6e 0a 65 33 62 30 63 34 34 32 39 38 66 63 31 63 31 34 39 61 66 62 66 34 63 38 39 39 36 66 62 39 32 34 32 37 61 65 34 31 65 34 36 34 39 62 39 33 34 63 61 34 39 35 39 39 31 62 37 38 35 32 62 38 35 35</CanonicalRequestBytes><RequestId>3EDF2BFB155307CF</RequestId><HostId>q5lLYag9EJC/liFWejbNHWgFPZUDMLG3bBP5xM2+u87HlsO4alkoEu5r7xIcOih+YPcGFeCVJ20=</HostId></Error>
Thanks John Rotenstein & Jordon Phillips for your help.
My issue got resolved by using boto3 for multipart. I was facing above issue with boto for multipart in eu-central-region

how to find duplicate values using row_number and partition by

I would like to know how to get all the duplicate values using the following query.please let me know what i am doing wrong with the query.
regards,
Iftekhar
SQL> desc tmp_emp_Area
Name Null? Type
------------------------------- -------- ----
SC_CD VARCHAR2(2)
DIST_CD VARCHAR2(2)
THA_CD VARCHAR2(2)
UN_CD VARCHAR2(3)
FP_ID VARCHAR2(4)
S_DT DATE
END_DT DATE
PERFORM VARCHAR2(1)
BS_CD VARCHAR2(4)
MKT_CD VARCHAR2(3)
Query :
SELECT SC_CD,DIST_CD,THA_CD,UN_CD,FP_ID,
row_number() over(partition BY SC_CD, DIST_CD, THA_CD, UN_CD, FP_ID order by FP_ID) rn
FROM tmp_emp_area
WHERE rn >1
SQL> / WHERE rn >1
* ERROR at line 4: ORA-00904: "RN": invalid identifier
Please check these two results below that i got after running two different queries to get duplicates.one is showing 92 columns and other is showing 96 columns.
select SC_CD,DIST_CD,THA_CD,UN_CD,FP_ID,count(fp_id)
from tmp_emp_area
group by SC_CD,DIST_CD,THA_CD,UN_CD,FP_ID
having count(fp_id)>1
/
SC DI TH UN_ FP_I COUNT(FP_ID)
-- -- -- --- ---- ------------
14 61 02 022 5J85 2
14 61 02 098 5J85 3
14 64 02 004 5J85 2
14 64 02 002 5J85 2
14 60 19 060 5F77 2
14 60 13 077 5F77 2
14 61 06 006 5D51 2
14 61 07 013 5D51 2
14 61 07 083 5D51 2
14 61 06 010 5D51 2
14 61 01 015 5R44 2
14 61 08 027 5R44 2
14 61 01 057 5R44 2
14 61 01 067 5R44 2
14 61 05 001 5R44 2
14 61 05 003 5R44 2
14 61 02 009 5J85 2
14 60 13 078 5F77 2
14 61 06 007 5D51 2
14 61 01 021 5R44 2
14 61 01 029 5R44 2
SC DI TH UN_ FP_I COUNT(FP_ID)
-- -- -- --- ---- ------------
14 61 01 065 5R44 2
14 61 01 069 5R44 2
14 64 03 013 5J85 2
14 61 02 014 5J85 2
14 61 02 089 5J85 2
14 60 19 132 5F77 2
14 60 19 134 5F77 2
14 61 07 086 5D51 2
14 61 06 035 5D51 2
14 61 06 014 5D51 2
14 61 01 031 5R44 2
14 61 01 036 5R44 2
14 61 01 041 5R44 2
14 61 02 092 5J85 3
14 61 02 074 5J85 3
14 61 02 088 5J85 2
14 61 02 109 5J85 2
14 60 19 014 5F77 2
14 61 07 015 5D51 2
14 61 06 008 5D51 2
14 61 06 016 5D51 2
SC DI TH UN_ FP_I COUNT(FP_ID)
-- -- -- --- ---- ------------
14 61 05 047 5R44 2
14 61 01 018 5R44 2
14 61 01 055 5R44 2
14 61 01 066 5R44 2
14 61 01 024 5R44 2
14 61 02 093 5J85 3
14 64 02 011 5J85 2
14 64 02 003 5J85 2
14 61 09 002 5J85 2
14 61 02 081 5J85 2
14 61 05 053 5D51 2
14 61 07 087 5D51 2
14 61 06 036 5D51 2
14 61 06 020 5D51 2
14 61 01 076 5R44 2
14 61 02 059 5R44 2
14 61 02 033 5J85 2
14 64 02 008 5J85 2
14 64 02 020 5J85 2
14 61 02 097 5J85 2
14 61 02 017 5J85 2
SC DI TH UN_ FP_I COUNT(FP_ID)
-- -- -- --- ---- ------------
14 61 02 082 5J85 2
14 61 01 077 5R44 2
14 61 05 046 5R44 2
14 61 01 017 5R44 2
14 61 01 054 5R44 2
14 64 02 030 5J85 2
14 61 02 010 5J85 2
14 61 02 103 5J85 2
14 64 02 006 5J85 2
14 64 03 020 5J85 2
14 61 02 105 5J85 2
14 61 02 080 5J85 2
14 61 02 151 5J85 2
14 60 19 059 5F77 2
14 61 06 045 5D51 2
14 61 01 075 5R44 2
14 61 01 056 5R44 2
14 61 01 020 5R44 2
14 61 05 007 5R44 2
14 61 01 053 5R44 2
14 61 01 078 5R44 2
SC DI TH UN_ FP_I COUNT(FP_ID)
-- -- -- --- ---- ------------
14 61 02 013 5J85 2
14 64 02 010 5J85 2
14 64 02 001 5J85 2
14 61 02 077 5J85 2
14 61 07 033 5D51 2
14 61 01 033 5R44 2
14 61 01 068 5R44 2
14 61 01 073 5R44 2
92 rows selected.
select *
from
(
SELECT SC_CD,DIST_CD,THA_CD,UN_CD,FP_ID,
row_number() over(partition BY SC_CD, DIST_CD, THA_CD, UN_CD, FP_ID order by FP_ID) rn
FROM tmp_emp_area
) dt
WHERE rn >1
SQL> /
SC DI TH UN_ FP_I RN
-- -- -- --- ---- ---------
14 60 13 077 5F77 2
14 60 13 078 5F77 2
14 60 19 014 5F77 2
14 60 19 059 5F77 2
14 60 19 060 5F77 2
14 60 19 132 5F77 2
14 60 19 134 5F77 2
14 61 01 015 5R44 2
14 61 01 017 5R44 2
14 61 01 018 5R44 2
14 61 01 020 5R44 2
14 61 01 021 5R44 2
14 61 01 024 5R44 2
14 61 01 029 5R44 2
14 61 01 031 5R44 2
14 61 01 033 5R44 2
14 61 01 036 5R44 2
14 61 01 041 5R44 2
14 61 01 053 5R44 2
14 61 01 054 5R44 2
14 61 01 055 5R44 2
SC DI TH UN_ FP_I RN
-- -- -- --- ---- ---------
14 61 01 056 5R44 2
14 61 01 057 5R44 2
14 61 01 065 5R44 2
14 61 01 066 5R44 2
14 61 01 067 5R44 2
14 61 01 068 5R44 2
14 61 01 069 5R44 2
14 61 01 073 5R44 2
14 61 01 075 5R44 2
14 61 01 076 5R44 2
14 61 01 077 5R44 2
14 61 01 078 5R44 2
14 61 02 009 5J85 2
14 61 02 010 5J85 2
14 61 02 013 5J85 2
14 61 02 014 5J85 2
14 61 02 017 5J85 2
14 61 02 022 5J85 2
14 61 02 033 5J85 2
14 61 02 059 5R44 2
14 61 02 074 5J85 2
SC DI TH UN_ FP_I RN
-- -- -- --- ---- ---------
14 61 02 074 5J85 3
14 61 02 077 5J85 2
14 61 02 080 5J85 2
14 61 02 081 5J85 2
14 61 02 082 5J85 2
14 61 02 088 5J85 2
14 61 02 089 5J85 2
14 61 02 092 5J85 2
14 61 02 092 5J85 3
14 61 02 093 5J85 2
14 61 02 093 5J85 3
14 61 02 097 5J85 2
14 61 02 098 5J85 2
14 61 02 098 5J85 3
14 61 02 103 5J85 2
14 61 02 105 5J85 2
14 61 02 109 5J85 2
14 61 02 151 5J85 2
14 61 05 001 5R44 2
14 61 05 003 5R44 2
14 61 05 007 5R44 2
SC DI TH UN_ FP_I RN
-- -- -- --- ---- ---------
14 61 05 046 5R44 2
14 61 05 047 5R44 2
14 61 05 053 5D51 2
14 61 06 006 5D51 2
14 61 06 007 5D51 2
14 61 06 008 5D51 2
14 61 06 010 5D51 2
14 61 06 014 5D51 2
14 61 06 016 5D51 2
14 61 06 020 5D51 2
14 61 06 035 5D51 2
14 61 06 036 5D51 2
14 61 06 045 5D51 2
14 61 07 013 5D51 2
14 61 07 015 5D51 2
14 61 07 033 5D51 2
14 61 07 083 5D51 2
14 61 07 086 5D51 2
14 61 07 087 5D51 2
14 61 08 027 5R44 2
14 61 09 002 5J85 2
SC DI TH UN_ FP_I RN
-- -- -- --- ---- ---------
14 64 02 001 5J85 2
14 64 02 002 5J85 2
14 64 02 003 5J85 2
14 64 02 004 5J85 2
14 64 02 006 5J85 2
14 64 02 008 5J85 2
14 64 02 010 5J85 2
14 64 02 011 5J85 2
14 64 02 020 5J85 2
14 64 02 030 5J85 2
14 64 03 013 5J85 2
14 64 03 020 5J85 2
96 rows selected.
You can't use an alias in WHERE, switch to a Derived Table:
select *
from
(
SELECT SC_CD,DIST_CD,THA_CD,UN_CD,FP_ID,
row_number() over(partition BY SC_CD, DIST_CD, THA_CD, UN_CD, FP_ID order by FP_ID) rn
FROM tmp_emp_area
) dt
WHERE rn >1