Help with sql code [message #664667] |
Wed, 26 July 2017 21:30 |
|
ramkumar10
Messages: 19 Registered: March 2017
|
Junior Member |
|
|
Hi I have a scenerio which I am not able to wrap my head around
I have a table with data like below
Acc Pol
A1 b1
A1 b2
A1 b3
A2 b4
A2 b5
and so on
Note: We have a maximum of 300 Pol for one acc i.e A1 can have B1,B2,.....upto 300
The requirement is I have to migrate this data as 1000 rows maximum as batch one and mark colc as 0 and the next 1000(max) rows the colC as 1 and so on. But the catch is all the pol under one acc should be migrated together.
example if there are 300 pol under acc A1,A2,A3 respectively and 50 pol under acc A4 and 60 pol under acc A5 then only 950 pol should be marked as 0 and remaining 60 pol of A5 should be marked as 1
expected output
acc pol id
A1 B1 0
A1 B2 0
. . 0
. . 0
. . 0
. . 0
A1 B300 0
A2 b301 0
. . .
. . .
A3 B300 0
. . 0
. . 0
. . 0
. . 0
A4 B300 0
. . 0
. . 0
. . 0
. . 0
A5 B50 0
. . 0
. . 0
. . 0
. . 0
A6 B60 1
Also sorry for the above formatting I tried my best to do it but this is how far I could do.
In the above o/p I only migrated 960 rows as batch 0 and remaining 60 rows as batch one cuz I can only have a maximum of 1000 records in each batch and all the pol for a record shuld be migrated together
please advice how to do it
thanks for any inputs.
[EDITED by LF: applied [code] tags to improve formatting]
[Updated on: Thu, 27 July 2017 01:06] by Moderator Report message to a moderator
|
|
|
|
Re: Help with sql code [message #664671 is a reply to message #664667] |
Thu, 27 July 2017 01:09 |
|
Michel Cadot
Messages: 68693 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Following the text and not the expected output which are inconsistent:
Quote:example if there are 300 pol under acc A1,A2,A3 respectively and 50 pol under acc A4 and 60 pol under acc A5 then only 950 pol should be marked as 0 and remaining 60 pol of A5 should be marked as 1
SQL> col acc format a3
SQL> col pol format a4
SQL> col batch format 99990
SQL> with acc as (select level acc from dual connect by level <= 5)
2 select 'A'||to_char(acc) acc,
3 'B'||to_char(column_value) pol,
4 trunc(count(*) over (order by acc range between unbounded preceding and current row)
5 / 1000) batch
6 from acc,
7 table(cast(multiset(select level from dual
8 connect by level <= case
9 when acc in (1,2,3) then 300
10 when acc = 4 then 50
11 when acc = 5 then 60
12 end)
13 as sys.odciNumberList))
14 order by acc, column_value
15 /
result
ACC POL BATCH
--- ---- ------
A1 B1 0
A1 B2 0
A1 B3 0
A1 B4 0
A1 B5 0
A1 B6 0
A1 B7 0
A1 B8 0
A1 B9 0
A1 B10 0
A1 B11 0
A1 B12 0
A1 B13 0
A1 B14 0
A1 B15 0
A1 B16 0
A1 B17 0
A1 B18 0
A1 B19 0
A1 B20 0
A1 B21 0
A1 B22 0
A1 B23 0
A1 B24 0
A1 B25 0
A1 B26 0
A1 B27 0
A1 B28 0
A1 B29 0
A1 B30 0
A1 B31 0
A1 B32 0
A1 B33 0
A1 B34 0
A1 B35 0
A1 B36 0
A1 B37 0
A1 B38 0
A1 B39 0
A1 B40 0
A1 B41 0
A1 B42 0
A1 B43 0
A1 B44 0
A1 B45 0
A1 B46 0
A1 B47 0
A1 B48 0
A1 B49 0
A1 B50 0
A1 B51 0
A1 B52 0
A1 B53 0
A1 B54 0
A1 B55 0
A1 B56 0
A1 B57 0
A1 B58 0
A1 B59 0
A1 B60 0
A1 B61 0
A1 B62 0
A1 B63 0
A1 B64 0
A1 B65 0
A1 B66 0
A1 B67 0
A1 B68 0
A1 B69 0
A1 B70 0
A1 B71 0
A1 B72 0
A1 B73 0
A1 B74 0
A1 B75 0
A1 B76 0
A1 B77 0
A1 B78 0
A1 B79 0
A1 B80 0
A1 B81 0
A1 B82 0
A1 B83 0
A1 B84 0
A1 B85 0
A1 B86 0
A1 B87 0
A1 B88 0
A1 B89 0
A1 B90 0
A1 B91 0
A1 B92 0
A1 B93 0
A1 B94 0
A1 B95 0
A1 B96 0
A1 B97 0
A1 B98 0
A1 B99 0
A1 B100 0
A1 B101 0
A1 B102 0
A1 B103 0
A1 B104 0
A1 B105 0
A1 B106 0
A1 B107 0
A1 B108 0
A1 B109 0
A1 B110 0
A1 B111 0
A1 B112 0
A1 B113 0
A1 B114 0
A1 B115 0
A1 B116 0
A1 B117 0
A1 B118 0
A1 B119 0
A1 B120 0
A1 B121 0
A1 B122 0
A1 B123 0
A1 B124 0
A1 B125 0
A1 B126 0
A1 B127 0
A1 B128 0
A1 B129 0
A1 B130 0
A1 B131 0
A1 B132 0
A1 B133 0
A1 B134 0
A1 B135 0
A1 B136 0
A1 B137 0
A1 B138 0
A1 B139 0
A1 B140 0
A1 B141 0
A1 B142 0
A1 B143 0
A1 B144 0
A1 B145 0
A1 B146 0
A1 B147 0
A1 B148 0
A1 B149 0
A1 B150 0
A1 B151 0
A1 B152 0
A1 B153 0
A1 B154 0
A1 B155 0
A1 B156 0
A1 B157 0
A1 B158 0
A1 B159 0
A1 B160 0
A1 B161 0
A1 B162 0
A1 B163 0
A1 B164 0
A1 B165 0
A1 B166 0
A1 B167 0
A1 B168 0
A1 B169 0
A1 B170 0
A1 B171 0
A1 B172 0
A1 B173 0
A1 B174 0
A1 B175 0
A1 B176 0
A1 B177 0
A1 B178 0
A1 B179 0
A1 B180 0
A1 B181 0
A1 B182 0
A1 B183 0
A1 B184 0
A1 B185 0
A1 B186 0
A1 B187 0
A1 B188 0
A1 B189 0
A1 B190 0
A1 B191 0
A1 B192 0
A1 B193 0
A1 B194 0
A1 B195 0
A1 B196 0
A1 B197 0
A1 B198 0
A1 B199 0
A1 B200 0
A1 B201 0
A1 B202 0
A1 B203 0
A1 B204 0
A1 B205 0
A1 B206 0
A1 B207 0
A1 B208 0
A1 B209 0
A1 B210 0
A1 B211 0
A1 B212 0
A1 B213 0
A1 B214 0
A1 B215 0
A1 B216 0
A1 B217 0
A1 B218 0
A1 B219 0
A1 B220 0
A1 B221 0
A1 B222 0
A1 B223 0
A1 B224 0
A1 B225 0
A1 B226 0
A1 B227 0
A1 B228 0
A1 B229 0
A1 B230 0
A1 B231 0
A1 B232 0
A1 B233 0
A1 B234 0
A1 B235 0
A1 B236 0
A1 B237 0
A1 B238 0
A1 B239 0
A1 B240 0
A1 B241 0
A1 B242 0
A1 B243 0
A1 B244 0
A1 B245 0
A1 B246 0
A1 B247 0
A1 B248 0
A1 B249 0
A1 B250 0
A1 B251 0
A1 B252 0
A1 B253 0
A1 B254 0
A1 B255 0
A1 B256 0
A1 B257 0
A1 B258 0
A1 B259 0
A1 B260 0
A1 B261 0
A1 B262 0
A1 B263 0
A1 B264 0
A1 B265 0
A1 B266 0
A1 B267 0
A1 B268 0
A1 B269 0
A1 B270 0
A1 B271 0
A1 B272 0
A1 B273 0
A1 B274 0
A1 B275 0
A1 B276 0
A1 B277 0
A1 B278 0
A1 B279 0
A1 B280 0
A1 B281 0
A1 B282 0
A1 B283 0
A1 B284 0
A1 B285 0
A1 B286 0
A1 B287 0
A1 B288 0
A1 B289 0
A1 B290 0
A1 B291 0
A1 B292 0
A1 B293 0
A1 B294 0
A1 B295 0
A1 B296 0
A1 B297 0
A1 B298 0
A1 B299 0
A1 B300 0
A2 B1 0
A2 B2 0
A2 B3 0
A2 B4 0
A2 B5 0
A2 B6 0
A2 B7 0
A2 B8 0
A2 B9 0
A2 B10 0
A2 B11 0
A2 B12 0
A2 B13 0
A2 B14 0
A2 B15 0
A2 B16 0
A2 B17 0
A2 B18 0
A2 B19 0
A2 B20 0
A2 B21 0
A2 B22 0
A2 B23 0
A2 B24 0
A2 B25 0
A2 B26 0
A2 B27 0
A2 B28 0
A2 B29 0
A2 B30 0
A2 B31 0
A2 B32 0
A2 B33 0
A2 B34 0
A2 B35 0
A2 B36 0
A2 B37 0
A2 B38 0
A2 B39 0
A2 B40 0
A2 B41 0
A2 B42 0
A2 B43 0
A2 B44 0
A2 B45 0
A2 B46 0
A2 B47 0
A2 B48 0
A2 B49 0
A2 B50 0
A2 B51 0
A2 B52 0
A2 B53 0
A2 B54 0
A2 B55 0
A2 B56 0
A2 B57 0
A2 B58 0
A2 B59 0
A2 B60 0
A2 B61 0
A2 B62 0
A2 B63 0
A2 B64 0
A2 B65 0
A2 B66 0
A2 B67 0
A2 B68 0
A2 B69 0
A2 B70 0
A2 B71 0
A2 B72 0
A2 B73 0
A2 B74 0
A2 B75 0
A2 B76 0
A2 B77 0
A2 B78 0
A2 B79 0
A2 B80 0
A2 B81 0
A2 B82 0
A2 B83 0
A2 B84 0
A2 B85 0
A2 B86 0
A2 B87 0
A2 B88 0
A2 B89 0
A2 B90 0
A2 B91 0
A2 B92 0
A2 B93 0
A2 B94 0
A2 B95 0
A2 B96 0
A2 B97 0
A2 B98 0
A2 B99 0
A2 B100 0
A2 B101 0
A2 B102 0
A2 B103 0
A2 B104 0
A2 B105 0
A2 B106 0
A2 B107 0
A2 B108 0
A2 B109 0
A2 B110 0
A2 B111 0
A2 B112 0
A2 B113 0
A2 B114 0
A2 B115 0
A2 B116 0
A2 B117 0
A2 B118 0
A2 B119 0
A2 B120 0
A2 B121 0
A2 B122 0
A2 B123 0
A2 B124 0
A2 B125 0
A2 B126 0
A2 B127 0
A2 B128 0
A2 B129 0
A2 B130 0
A2 B131 0
A2 B132 0
A2 B133 0
A2 B134 0
A2 B135 0
A2 B136 0
A2 B137 0
A2 B138 0
A2 B139 0
A2 B140 0
A2 B141 0
A2 B142 0
A2 B143 0
A2 B144 0
A2 B145 0
A2 B146 0
A2 B147 0
A2 B148 0
A2 B149 0
A2 B150 0
A2 B151 0
A2 B152 0
A2 B153 0
A2 B154 0
A2 B155 0
A2 B156 0
A2 B157 0
A2 B158 0
A2 B159 0
A2 B160 0
A2 B161 0
A2 B162 0
A2 B163 0
A2 B164 0
A2 B165 0
A2 B166 0
A2 B167 0
A2 B168 0
A2 B169 0
A2 B170 0
A2 B171 0
A2 B172 0
A2 B173 0
A2 B174 0
A2 B175 0
A2 B176 0
A2 B177 0
A2 B178 0
A2 B179 0
A2 B180 0
A2 B181 0
A2 B182 0
A2 B183 0
A2 B184 0
A2 B185 0
A2 B186 0
A2 B187 0
A2 B188 0
A2 B189 0
A2 B190 0
A2 B191 0
A2 B192 0
A2 B193 0
A2 B194 0
A2 B195 0
A2 B196 0
A2 B197 0
A2 B198 0
A2 B199 0
A2 B200 0
A2 B201 0
A2 B202 0
A2 B203 0
A2 B204 0
A2 B205 0
A2 B206 0
A2 B207 0
A2 B208 0
A2 B209 0
A2 B210 0
A2 B211 0
A2 B212 0
A2 B213 0
A2 B214 0
A2 B215 0
A2 B216 0
A2 B217 0
A2 B218 0
A2 B219 0
A2 B220 0
A2 B221 0
A2 B222 0
A2 B223 0
A2 B224 0
A2 B225 0
A2 B226 0
A2 B227 0
A2 B228 0
A2 B229 0
A2 B230 0
A2 B231 0
A2 B232 0
A2 B233 0
A2 B234 0
A2 B235 0
A2 B236 0
A2 B237 0
A2 B238 0
A2 B239 0
A2 B240 0
A2 B241 0
A2 B242 0
A2 B243 0
A2 B244 0
A2 B245 0
A2 B246 0
A2 B247 0
A2 B248 0
A2 B249 0
A2 B250 0
A2 B251 0
A2 B252 0
A2 B253 0
A2 B254 0
A2 B255 0
A2 B256 0
A2 B257 0
A2 B258 0
A2 B259 0
A2 B260 0
A2 B261 0
A2 B262 0
A2 B263 0
A2 B264 0
A2 B265 0
A2 B266 0
A2 B267 0
A2 B268 0
A2 B269 0
A2 B270 0
A2 B271 0
A2 B272 0
A2 B273 0
A2 B274 0
A2 B275 0
A2 B276 0
A2 B277 0
A2 B278 0
A2 B279 0
A2 B280 0
A2 B281 0
A2 B282 0
A2 B283 0
A2 B284 0
A2 B285 0
A2 B286 0
A2 B287 0
A2 B288 0
A2 B289 0
A2 B290 0
A2 B291 0
A2 B292 0
A2 B293 0
A2 B294 0
A2 B295 0
A2 B296 0
A2 B297 0
A2 B298 0
A2 B299 0
A2 B300 0
A3 B1 0
A3 B2 0
A3 B3 0
A3 B4 0
A3 B5 0
A3 B6 0
A3 B7 0
A3 B8 0
A3 B9 0
A3 B10 0
A3 B11 0
A3 B12 0
A3 B13 0
A3 B14 0
A3 B15 0
A3 B16 0
A3 B17 0
A3 B18 0
A3 B19 0
A3 B20 0
A3 B21 0
A3 B22 0
A3 B23 0
A3 B24 0
A3 B25 0
A3 B26 0
A3 B27 0
A3 B28 0
A3 B29 0
A3 B30 0
A3 B31 0
A3 B32 0
A3 B33 0
A3 B34 0
A3 B35 0
A3 B36 0
A3 B37 0
A3 B38 0
A3 B39 0
A3 B40 0
A3 B41 0
A3 B42 0
A3 B43 0
A3 B44 0
A3 B45 0
A3 B46 0
A3 B47 0
A3 B48 0
A3 B49 0
A3 B50 0
A3 B51 0
A3 B52 0
A3 B53 0
A3 B54 0
A3 B55 0
A3 B56 0
A3 B57 0
A3 B58 0
A3 B59 0
A3 B60 0
A3 B61 0
A3 B62 0
A3 B63 0
A3 B64 0
A3 B65 0
A3 B66 0
A3 B67 0
A3 B68 0
A3 B69 0
A3 B70 0
A3 B71 0
A3 B72 0
A3 B73 0
A3 B74 0
A3 B75 0
A3 B76 0
A3 B77 0
A3 B78 0
A3 B79 0
A3 B80 0
A3 B81 0
A3 B82 0
A3 B83 0
A3 B84 0
A3 B85 0
A3 B86 0
A3 B87 0
A3 B88 0
A3 B89 0
A3 B90 0
A3 B91 0
A3 B92 0
A3 B93 0
A3 B94 0
A3 B95 0
A3 B96 0
A3 B97 0
A3 B98 0
A3 B99 0
A3 B100 0
A3 B101 0
A3 B102 0
A3 B103 0
A3 B104 0
A3 B105 0
A3 B106 0
A3 B107 0
A3 B108 0
A3 B109 0
A3 B110 0
A3 B111 0
A3 B112 0
A3 B113 0
A3 B114 0
A3 B115 0
A3 B116 0
A3 B117 0
A3 B118 0
A3 B119 0
A3 B120 0
A3 B121 0
A3 B122 0
A3 B123 0
A3 B124 0
A3 B125 0
A3 B126 0
A3 B127 0
A3 B128 0
A3 B129 0
A3 B130 0
A3 B131 0
A3 B132 0
A3 B133 0
A3 B134 0
A3 B135 0
A3 B136 0
A3 B137 0
A3 B138 0
A3 B139 0
A3 B140 0
A3 B141 0
A3 B142 0
A3 B143 0
A3 B144 0
A3 B145 0
A3 B146 0
A3 B147 0
A3 B148 0
A3 B149 0
A3 B150 0
A3 B151 0
A3 B152 0
A3 B153 0
A3 B154 0
A3 B155 0
A3 B156 0
A3 B157 0
A3 B158 0
A3 B159 0
A3 B160 0
A3 B161 0
A3 B162 0
A3 B163 0
A3 B164 0
A3 B165 0
A3 B166 0
A3 B167 0
A3 B168 0
A3 B169 0
A3 B170 0
A3 B171 0
A3 B172 0
A3 B173 0
A3 B174 0
A3 B175 0
A3 B176 0
A3 B177 0
A3 B178 0
A3 B179 0
A3 B180 0
A3 B181 0
A3 B182 0
A3 B183 0
A3 B184 0
A3 B185 0
A3 B186 0
A3 B187 0
A3 B188 0
A3 B189 0
A3 B190 0
A3 B191 0
A3 B192 0
A3 B193 0
A3 B194 0
A3 B195 0
A3 B196 0
A3 B197 0
A3 B198 0
A3 B199 0
A3 B200 0
A3 B201 0
A3 B202 0
A3 B203 0
A3 B204 0
A3 B205 0
A3 B206 0
A3 B207 0
A3 B208 0
A3 B209 0
A3 B210 0
A3 B211 0
A3 B212 0
A3 B213 0
A3 B214 0
A3 B215 0
A3 B216 0
A3 B217 0
A3 B218 0
A3 B219 0
A3 B220 0
A3 B221 0
A3 B222 0
A3 B223 0
A3 B224 0
A3 B225 0
A3 B226 0
A3 B227 0
A3 B228 0
A3 B229 0
A3 B230 0
A3 B231 0
A3 B232 0
A3 B233 0
A3 B234 0
A3 B235 0
A3 B236 0
A3 B237 0
A3 B238 0
A3 B239 0
A3 B240 0
A3 B241 0
A3 B242 0
A3 B243 0
A3 B244 0
A3 B245 0
A3 B246 0
A3 B247 0
A3 B248 0
A3 B249 0
A3 B250 0
A3 B251 0
A3 B252 0
A3 B253 0
A3 B254 0
A3 B255 0
A3 B256 0
A3 B257 0
A3 B258 0
A3 B259 0
A3 B260 0
A3 B261 0
A3 B262 0
A3 B263 0
A3 B264 0
A3 B265 0
A3 B266 0
A3 B267 0
A3 B268 0
A3 B269 0
A3 B270 0
A3 B271 0
A3 B272 0
A3 B273 0
A3 B274 0
A3 B275 0
A3 B276 0
A3 B277 0
A3 B278 0
A3 B279 0
A3 B280 0
A3 B281 0
A3 B282 0
A3 B283 0
A3 B284 0
A3 B285 0
A3 B286 0
A3 B287 0
A3 B288 0
A3 B289 0
A3 B290 0
A3 B291 0
A3 B292 0
A3 B293 0
A3 B294 0
A3 B295 0
A3 B296 0
A3 B297 0
A3 B298 0
A3 B299 0
A3 B300 0
A4 B1 0
A4 B2 0
A4 B3 0
A4 B4 0
A4 B5 0
A4 B6 0
A4 B7 0
A4 B8 0
A4 B9 0
A4 B10 0
A4 B11 0
A4 B12 0
A4 B13 0
A4 B14 0
A4 B15 0
A4 B16 0
A4 B17 0
A4 B18 0
A4 B19 0
A4 B20 0
A4 B21 0
A4 B22 0
A4 B23 0
A4 B24 0
A4 B25 0
A4 B26 0
A4 B27 0
A4 B28 0
A4 B29 0
A4 B30 0
A4 B31 0
A4 B32 0
A4 B33 0
A4 B34 0
A4 B35 0
A4 B36 0
A4 B37 0
A4 B38 0
A4 B39 0
A4 B40 0
A4 B41 0
A4 B42 0
A4 B43 0
A4 B44 0
A4 B45 0
A4 B46 0
A4 B47 0
A4 B48 0
A4 B49 0
A4 B50 0
A5 B1 1
A5 B2 1
A5 B3 1
A5 B4 1
A5 B5 1
A5 B6 1
A5 B7 1
A5 B8 1
A5 B9 1
A5 B10 1
A5 B11 1
A5 B12 1
A5 B13 1
A5 B14 1
A5 B15 1
A5 B16 1
A5 B17 1
A5 B18 1
A5 B19 1
A5 B20 1
A5 B21 1
A5 B22 1
A5 B23 1
A5 B24 1
A5 B25 1
A5 B26 1
A5 B27 1
A5 B28 1
A5 B29 1
A5 B30 1
A5 B31 1
A5 B32 1
A5 B33 1
A5 B34 1
A5 B35 1
A5 B36 1
A5 B37 1
A5 B38 1
A5 B39 1
A5 B40 1
A5 B41 1
A5 B42 1
A5 B43 1
A5 B44 1
A5 B45 1
A5 B46 1
A5 B47 1
A5 B48 1
A5 B49 1
A5 B50 1
A5 B51 1
A5 B52 1
A5 B53 1
A5 B54 1
A5 B55 1
A5 B56 1
A5 B57 1
A5 B58 1
A5 B59 1
A5 B60 1
1010 rows selected.
[Updated on: Thu, 27 July 2017 01:11] Report message to a moderator
|
|
|
|
Re: Help with sql code [message #664681 is a reply to message #664671] |
Thu, 27 July 2017 22:45 |
|
ramkumar10
Messages: 19 Registered: March 2017
|
Junior Member |
|
|
Hey thanks for your time I have done the scenerio using ETL tool. To be honest my sql skills are intermediate level so If u get some time and are feeling like it I would appreciate if you could show me how to do this scenerio in sql.
Again thank-you.
|
|
|