Replicate a string names x times and ascribe replication number - awk

I would like to replicate key names x number of times and have a separate column to indicate the replication number, e.g. let's say I have three key names as follows:
101
102
103
So, I would like each of the above numbers (names) replicated 3 times and to have a separate identifier number equal to 4 characters. It would therefore look like this:
101 0001
101 0002
101 0003
102 0001
102 0002
102 0003
103 0001
103 0002
103 0003
I guess this could be genered with a relatively straight forward awk script? *Edit: I would like to not specify the names to replicate in the script - it should be "replicate all names in this text file", as there are a lot of them (~400) and all with variable name types.
Thank you in advance!

In bash
echo {101,102,103}" "{01,02,03}
101 01 101 02 101 03 102 01 102 02 102 03 103 01 103 02 103 03
Following Fedorqui's advice for newlines
printf "%s\n" {101,102,103}" "{01,02,03}
101 01
101 02
101 03
102 01
102 02
102 03
103 01
103 02
103 03

Using the awk -v flag to pass a variable number which is the number of repeats for each line, and sprint to format the number into 2 decimal places with zero padding:
awk -v number_repeats=3 '{
for(i=0; i<number_repeats; i++) {
print $0, sprintf("%02d", i+1)
}
}'

If you don't mind GNU Parallel
parallel -k 'printf "%02d %02d\n"' ::: {6..12} ::: 1 2 3
06 01
06 02
06 03
07 01
07 02
07 03
08 01
08 02
08 03
09 01
09 02
09 03
10 01
10 02
10 03
11 01
11 02
11 03
12 01
12 02
12 03
Or, if your keys are in a file, called keys like this
32
45
78
You can read the file
parallel -k 'printf "%02d %02d\n" {1} {2}' :::: keys ::: 1 2 3
32 01
32 02
32 03
45 01
45 02
45 03
78 01
78 02
78 03

Related

SQL statement for trial balance to display from table with one column of debit minus credit amount

I need trial balance from following tables:
Table: Journal
ID
TransactionDate
AccountCodeLevel1VarChar
AccountCodeLevel2VarChar
AccountCodeLevel3VarChar
AccountCodeLevel4VarChar
AccountCodeLevel5VarChar
AccountCodeLevel6VarChar
DebitAmountDecimal
CreditAmountDecimal
DescriptionVarchar
1
2022-1-1
1
01
01
01
001
001
1
Received cash from issuing common stocks
2
2022-1-1
3
01
01
01
001
001
1
Received cash from issuing common stocks
3
2022-1-1
1
01
01
01
001
001
2
Received cash borrowed from bank
4
2022-1-1
2
01
01
01
001
001
2
Received cash borrowed from bank
5
2022-1-1
1
01
01
01
001
001
3
Received cash borrowed from bank
6
2022-1-1
2
01
01
01
001
001
3
Received cash borrowed from bank
7
2022-1-1
1
01
01
01
001
001
4
Received cash from selling products
8
2022-1-1
4
01
01
01
001
001
4
Received cash from selling products
9
2022-1-1
1
01
01
01
001
001
5
Collected cash from services rendered
10
2022-1-1
4
02
01
01
001
001
5
Collected cash from services rendered
11
2022-1-1
5
01
01
01
001
001
6
Paid employee salaries
12
2022-1-1
1
01
01
01
001
001
6
Paid employee salaries
Table: AccountCode
AccountCodeLevel1VarChar
AccountCodeLevel2VarChar
AccountCodeLevel3VarChar
AccountCodeLevel4VarChar
AccountCodeLevel5VarChar
AccountCodeLevel6VarChar
AccountNameVarChar
1
01
01
01
001
001
Cash
2
01
01
01
001
001
Loan from banks
3
01
01
01
001
001
Paid-up common shares
4
01
01
01
001
001
Service revenue
4
02
01
01
001
001
Sales revenue
5
01
01
01
001
001
Salary
How can I get the SQL to render the summary result as shown hereunder with DebitAmountDecimal minus CreditAmountDecimal?
AccountCodeLevel1VarChar
AccountCodeLevel2VarChar
AccountCodeLevel3VarChar
AccountCodeLevel4VarChar
AccountCodeLevel5VarChar
AccountCodeLevel6VarChar
AccountNameVarChar
TrialBalanceAmount
1
01
01
01
001
001
Cash
9
2
01
01
01
001
001
Loan from banks
-5
3
01
01
01
001
001
Paid-up common shares
-1
4
01
01
01
001
001
Service revenue
-4
4
02
01
01
001
001
Sales revenue
-5
5
01
01
01
001
001
Salary
6
I tried to do with this SQL statement but the result is wrong:
SELECT
"ACC"."AccountCodeLevel1VarChar",
"ACC"."AccountCodeLevel2VarChar",
"ACC"."AccountCodeLevel3VarChar",
"ACC"."AccountCodeLevel4VarChar",
"ACC"."AccountCodeLevel5VarChar",
"ACC"."AccountCodeLevel6VarChar",
"ACC"."AccountNameVarChar",
SUM( "JNL"."DebitAmountDecimal" - "JNL"."CreditAmountDecimal" ) "TrialBalanceAmount"
FROM
"AccountCode" "ACC", "Journal" "JNL"
WHERE
"ACC"."AccountCodeLevel1VarChar" = "JNL"."AccountCodeLevel1VarChar"
AND
"ACC"."AccountCodeLevel2VarChar" = "JNL"."AccountCodeLevel2VarChar"
AND
"ACC"."AccountCodeLevel3VarChar" = "JNL"."AccountCodeLevel3VarChar"
AND
"ACC"."AccountCodeLevel4VarChar" = "JNL"."AccountCodeLevel4VarChar"
AND
"ACC"."AccountCodeLevel5VarChar" = "JNL"."AccountCodeLevel5VarChar"
AND
"ACC"."AccountCodeLevel6VarChar" = "JNL"."AccountCodeLevel6VarChar"
GROUP BY
"ACC"."AccountCodeLevel1VarChar",
"ACC"."AccountCodeLevel2VarChar",
"ACC"."AccountCodeLevel3VarChar",
"ACC"."AccountCodeLevel4VarChar",
"ACC"."AccountCodeLevel5VarChar",
"ACC"."AccountCodeLevel6VarChar",
"ACC"."AccountNameVarChar"
ORDER BY
"ACC"."AccountCodeLevel1VarChar" ASC,
"ACC"."AccountCodeLevel2VarChar" ASC,
"ACC"."AccountCodeLevel3VarChar" ASC,
"ACC"."AccountCodeLevel4VarChar" ASC,
"ACC"."AccountCodeLevel5VarChar" ASC,
"ACC"."AccountCodeLevel6VarChar" ASC
Thank you so much #Mark Rotteveel for the comment that I was summing NULL.
SUM( COALESCE ( "JNL"."DebitAmountDecimal", 0 ) ) - SUM( COALESCE ( "JNL"."CreditAmountDecimal", 0 ) ) "TrialBalanceAmount"
Now the result is complete.

Decode Proprietary Data GPRMC Data - Yamaha GPS Data logger

This is a long shot, but I have been trying to convert a .ctrk file which has been downloaded from a Yamaha Motorbike Data logger to a readable format.
If I open the file with Notepad++ there is some readable text, mostly the GPRMC data which I can convert to GPS coordinates, speed, time, etc... however the file 'should' also contain 18(i think) other data points(Lean angles, engine RPMs, G forces etc...).
In Notepad++ the data between the GPRMC data just shows as Start of headers, Null, Escape characters,(ENO,DC4,EOT,STX) and such like.
RAW data in Hex
24 47 50 52 4D 43 2C 30 34 32 37 32 35 2E 38 30 30 2C 41 2C 33 33 34 38 2E 32 33 31 38 2C 53 2C 31 35 30 35 32 2E 32 31 31 30 2C 45 2C 30 2E 30 32 2C 32 37 36 2E 35 38 2C 32 30 30 32 31 35 2C 2C 2C 44 2A 37 35 0D 0A 01 00 19 00 C6 02 19 1B 04 05 14 02 DF 07 09 02 00 00 06 0D A9 00 06 00 80 01 00 1B 00 EA 02 19 1B 04 05 14 02 DF 07 11 05 00 00 08 96 7C 50 6A 58 2C 60 10 01 00 1B 00 EA 02 19 1B 04 05 14 02 DF 07 1B 05 00 00 08 FF FF FF FF 80 00 00 00 01 00 1A 00 FE 02 19 1B 04 05 14 02 DF 07 26 02 00 00 07 0C E8 E8 EB E8 28 40 01 00 1B 00 0C 03 19 1B 04 05 14 02 DF 07 15 02 00 00 08 00 06 00 01 F3 22 06 00 01 00 1B 00 0F 03 19 1B 04 05 14 02 DF 07 58 02 00 00 08 52 16 B1 7B 00 00 75 46 01 00 1B 00 13 03 19 1B 04 05 14 02 DF 07 60 02 00 00 08 00 02 00 93 00 00 00 8C 01 00 17 00 1D 03 19 1B 04 05 14 02 DF 07 64 02 00 00 04 00 00 00 00 01 00 19 00 1D 03 19 1B 04 05 14 02 DF 07 68 02 00 00 06 00 00 00 00 04 00 01 00 1B 00 23 03 19 1B 04 05 14 02 DF 07 50 02 00 00 08 1B 48 1B 0A 1F 40 20 00 02 00 56 00 26 03 19 1B 04 05 14 02 DF 07 24 47 50 52 4D 43 2C 30 34 32 37 32 35 2E 39 30 30 2C 41 2C 33 33 34 38 2E 32 33 31 38 2C 53 2C 31 35 30 35 32 2E 32 31 31 30 2C 45 2C 30 2E 30 32 2C 32 37 36 2E 35 38 2C 32 30 30 32 31 35 2C 2C 2C 44 2A 37 34
Any ideas how I'd go about decoding this data which I'm assuming is a proprietary format. I have no idea where to start.
Thanks
James
Data in Hex editor
[1]:https://imgur.com/a/A7hlqH5

Oracle SQL - Sum Partition over ID but exclude repeated

My Table :
HEAD_ID LINE ID ADJUST_ID LIST_PRICE DISCOUNT
01 01 01 200 15
01 01 02 200 0
01 01 03 200 10
01 02 01 300 16
01 02 02 300 0
02 01 01 300 15
02 01 02 300 0
02 01 03 300 10
02 02 01 100 16
02 02 02 100 0
I need a sum over LIST_PRICE group by HEAD_ID and LINE_ID but exclude the ADJUST_ID. The TOTAL_LIST_PRICE should be the sum of all line ID from a head id but not repeated. For example :
For the TOTAL_LIST_PRICE for HEAD_ID 01 is (HEAD_ID 01 LINE_ID 01) + (HEAD_ID 01 LINE_ID 02) = 200 + 300 = 500
For the TOTAL_LIST_PRICE for HEAD_ID 02 is (HEAD_ID 02 LINE_ID 01) + (HEAD_ID 02 LINE_ID 02) = 300 + 105 = 405
Result expected is like this :
HEAD_ID LINE ID ADJUST_ID LIST_PRICE DISCOUNT TOTAL_LIST_PRICE
01 01 01 200 15 500
01 01 02 200 0 500
01 01 03 200 10 500
01 02 01 300 16 500
01 02 02 300 0 500
02 01 01 300 15 405
02 01 02 300 0 405
02 01 03 300 10 405
02 02 01 105 16 405
02 02 02 105 0 405
MY query is like this -
SELECT head_id, line_id, adjust_id, list_price, discount,
SUM(LIST_PRICE) OVER (PARTITION BY head_id, line_id) TOTAL_LIST_PRICE
FROM TABLE;
The output -
HEAD_ID LINE ID ADJUST_ID LIST_PRICE DISCOUNT TOTAL_LIST_PRICE
01 01 01 200 15 600
01 01 02 200 0 600
01 01 03 200 10 600
01 02 01 300 16 600
01 02 02 300 0 600
02 01 01 300 15 900
02 01 02 300 0 900
02 01 03 300 10 900
02 02 01 105 16 210
02 02 02 105 0 210
Is there anything I missing in the SUM OVER PARTITION? Or I'm using a wrong approach for this?
Thanks
You can use the ROW_NUMBER analytic function and PARTITION BY Head_id, Line_id, List_Price which will number each row for that partition and then filtering when that ROW_NUMBER is 1 will give the unique List_Price for each Head_id, Line_id which just needs to be SUMmed for each Head_id to give your desired output:
SQL Fiddle
Oracle 11g R2 Schema Setup:
CREATE TABLE table_name ( HEAD_ID, LINE_ID, ADJUST_ID, LIST_PRICE, DISCOUNT ) AS
SELECT '01', '01', '01', 200, 15 FROM DUAL UNION ALL
SELECT '01', '01', '02', 200, 0 FROM DUAL UNION ALL
SELECT '01', '01', '03', 200, 10 FROM DUAL UNION ALL
SELECT '01', '02', '01', 300, 16 FROM DUAL UNION ALL
SELECT '01', '02', '02', 300, 0 FROM DUAL UNION ALL
SELECT '02', '01', '01', 300, 15 FROM DUAL UNION ALL
SELECT '02', '01', '02', 300, 0 FROM DUAL UNION ALL
SELECT '02', '01', '03', 300, 10 FROM DUAL UNION ALL
SELECT '02', '02', '01', 100, 16 FROM DUAL UNION ALL
SELECT '02', '02', '02', 100, 0 FROM DUAL;
Query 1:
SELECT HEAD_ID,
LINE_ID,
ADJUST_ID,
LIST_PRICE,
DISCOUNT,
SUM( CASE rn WHEN 1 THEN LIST_PRICE END ) OVER ( PARTITION BY Head_id )
AS total_list_price
FROM (
SELECT t.*,
ROW_NUMBER() OVER ( PARTITION BY Head_id, Line_id, List_Price
ORDER BY ROWNUM ) AS rn
FROM table_name t
)
Results:
| HEAD_ID | LINE_ID | ADJUST_ID | LIST_PRICE | DISCOUNT | TOTAL_LIST_PRICE |
|---------|---------|-----------|------------|----------|------------------|
| 01 | 01 | 01 | 200 | 15 | 500 |
| 01 | 01 | 02 | 200 | 0 | 500 |
| 01 | 01 | 03 | 200 | 10 | 500 |
| 01 | 02 | 01 | 300 | 16 | 500 |
| 01 | 02 | 02 | 300 | 0 | 500 |
| 02 | 01 | 01 | 300 | 15 | 400 |
| 02 | 01 | 02 | 300 | 0 | 400 |
| 02 | 01 | 03 | 300 | 10 | 400 |
| 02 | 02 | 01 | 100 | 16 | 400 |
| 02 | 02 | 02 | 100 | 0 | 400 |
select head_id,
line_id,
adjust_id,
list_price,
discount,
sum(case when fl = 1 then list_price end) over(partition by head_id) total_list_price
from (select head_id, line_id, adjust_id, list_price, discount,
row_number()over(partition by head_id, line_id order by head_id) fl
from tab) q;

writing an sql query to display specific charges

I am writing an sql query to display names of guests who have incurred both athletic and dinner charges on their itinerary. Can someone point me in the right direction as to setting up the query?
this is what i have but gives no result..
SELECT GUEST.FIRSTNAME, CHARGETYPE.DESCRIPTION
FROM GUEST, CHARGES, CHARGETYPE
WHERE CHARGETYPE.CHARGEID = CHARGES.CHARGEID
AND CHARGES.CHARGEID = '07'
AND CHARGES.CHARGEID = '03'
the chargeid 07 and 03 reflect athletic and dinner charges respectfully. im sorry for the lack of info, first time really using stackoverflow.
Here is the CHARGETYPE table
CHARGEID and DESCRIPTION are the column names
01 ROOM DEPOSIT
02 LUNCH SERVICE
03 DINNER SERVICE
04 BREAKFAST SERVICE
05 ROOM CHARGE
06 GIFTSHOP PURCHASE
07 ATHLETIC CHARGE
CHARGEID, ITINID, CHARGETIME, AMOUNT, GUESTID are the columns for the CHARGES table
01 001 11:00 -1850001
02 001 14:00 30 0001
03 001 18:00 55 0001
04 001 11:00 20 0001
05 001 20:00 20 0001
08 001 12:00 20 0001
01 002 16:00 -185 0002
02 002 16:30 40 0002
04 002 10:00 20 0002
05 002 14:00 25 0002
09 002 15:00 25 0002
01 003 10:00 -185 0003
02 003 12:00 30 0003
03 003 18:00 50 0003
04 003 11:00 18 0003
05 003 12:30 27 0003
06 003 14:45 30 0003
01 004 11:00 -185 0004
02 004 13:00 40 0004
03 004 19:00 60 0004
04 004 11:00 15 0004
05 004 20:00 34 0004
01 005 10:00 -185 0005
02 005 12:00 30 0005
03 005 17:00 30 0005
04 005 10:00 10 0005
05 005 16:00 25 0005
01 006 11:00 -185 0001
02 006 12:00 22 0001
03 006 18:00 40 0001
04 006 08:00 15 0001
05 006 20:00 60 0001
07 006 14:00 50 0001
01 007 11:00 -185 0003
02 007 12:00 20 0003
03 007 17:00 55 0003
04 007 10:00 15 0003
05 007 16:00 45 0003
01 008 11:00 -185 0005
02 008 13:00 20 0005
03 008 18:00 60 0005
04 008 09:00 20 0005
05 008 22:00 65 0005
07 008 12:00 50 0005
.
GUESTID LASTNAME FIRSTNAME are the columns for the GUEST table
0001 SMITH JOHN
0002 SMITH LISA
0003 ADAMS PETER
0004 ADAMS JANE
0005 JOHNSON DEAN
SELECT G.FIRSTNAME,G.LASTNAME, CT.DESCRIPTION
FROM GUEST G
INNER JOIN CHARGETYPE CT
ON G.GUESTID = C.GUESTID
INNER JOIN CHARGES
ON CT.CHARGEID = C.CHARGEID
WHERE C.CHARGEID IN ('07','03' );

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