How to write sql to do one aggregation over another - sql

Sample data
WITH
tbl AS
(
Select 'UK' "CUST_GRP", '00001' "CUST_ID", 'John' "CUST_NAME", '001' "ORDER_ID", 'Beer' "GOODS" From Dual Union All
Select 'ITA' "CUST_GRP", '00002' "CUST_ID", 'Jack' "CUST_NAME", '002' "ORDER_ID", 'Coca Cola' "GOODS" From Dual Union All
Select 'ITA' "CUST_GRP", '00002' "CUST_ID", 'Jack' "CUST_NAME", '003' "ORDER_ID", 'Fanta' "GOODS" From Dual Union All
Select 'ITA' "CUST_GRP", '00003' "CUST_ID", 'Lisa' "CUST_NAME", '004' "ORDER_ID", 'Beer' "GOODS" From Dual Union All
Select 'ITA' "CUST_GRP", '00003' "CUST_ID", 'Lisa' "CUST_NAME", '005' "ORDER_ID", 'Coffee' "GOODS" From Dual Union All
Select 'FRA' "CUST_GRP", '00004' "CUST_ID", 'Messi' "CUST_NAME", '006' "ORDER_ID", 'Wine' "GOODS" From Dual Union All
Select 'FRA' "CUST_GRP", '00004' "CUST_ID", 'Messi' "CUST_NAME", '007' "ORDER_ID", 'Juice' "GOODS" From Dual Union All
Select 'FRA' "CUST_GRP", '00004' "CUST_ID", 'Messi' "CUST_NAME", '008' "ORDER_ID", 'Beer' "GOODS" From Dual Union All
Select 'FRA' "CUST_GRP", '00005' "CUST_ID", 'Mary' "CUST_NAME", '009' "ORDER_ID", 'Wine' "GOODS" From Dual Union All
Select 'FRA' "CUST_GRP", '00005' "CUST_ID", 'Mary' "CUST_NAME", '020' "ORDER_ID", 'Else' "GOODS" From Dual
)
I need to know the number of customers that have done the same number of orders.
Expected result should be either
TEXT
the amount of customers who ordered 1 times is 1
the amount of customers who ordered 2 times is 3
the amount of customers who ordered 3 times is 1
OR
Orders
Customers
1
1
2
3
3
1
Anyone can tell me how to write this SQL ?

This will get you the desired results. You are grouping by customer to find out how many orders they placed. Then grouping that subset as well.
select orders, count(*) customers
from (
select cust_id, count(*) orders
from tbl
group by cust_id
)
group by orders

Related

SQL query to find products which have different values for a particular id which should be the same

I need a SQL query which will fetch me the list of products which has different values for a same id and product is of table A and Id and values are of table B and both the tables can be joined by column name prod_id
Output I want:
List item
product
abc
So in output I want only the product abc because it has different values for their respective id and I don’t need xyz because it has same values for their respective id
I tried but I’m not getting what I want as mentioned above
select distinct product
from your_table
group by product, id
having count(distinct values) > 1
If I got it right, you have two tables - one with PROD_ID and PRODUCT and the other with PROD_ID, ID, VALS - something like this:
WITH
tbl_a AS
(
Select 1 "PROD_ID", 'abc' "PRODUCT" From DUAL Union All
Select 9 "PROD_ID", 'xyz' "PRODUCT" From DUAL
),
tbl_b AS
(
Select 1 "PROD_ID", '10' "ID", 345678 "VALS" From DUAL Union All
Select 1 "PROD_ID", '10' "ID", 345678 "VALS" From DUAL Union All
Select 1 "PROD_ID", '14' "ID", 458292 "VALS" From DUAL Union All
Select 1 "PROD_ID", '13' "ID", 629351 "VALS" From DUAL Union All
Select 1 "PROD_ID", '13' "ID", 629354 "VALS" From DUAL Union All
Select 9 "PROD_ID", '10' "ID", 375281 "VALS" From DUAL Union All
Select 9 "PROD_ID", '10' "ID", 375281 "VALS" From DUAL Union All
Select 9 "PROD_ID", '12' "ID", 826292 "VALS" From DUAL Union All
Select 9 "PROD_ID", '12' "ID", 826292 "VALS" From DUAL
)
Now, if this is the case, all you have to do is to join the tables by PROD_ID and select the product having more than one distinct value of VALS column grouped by PRODUCT and ID:
Select
a.PRODUCT
From
tbl_a a
Inner Join
tbl_b b ON(b.PROD_ID = a.PROD_ID)
Group By
a.PRODUCT, b.ID
Having
Count(DISTINCT b.VALS) > 1
--
-- Result:
-- PRODUCT
-- -------
-- abc

Order a SQL SELECT by a IN selection

I have a SELECT based on a IN
I want to order the extraction in the same order I made the IN. How can I make it?
SELECT * FROM BOLLER1 WHERE BOLR1_KT1 IN ('TM2019000026000010',
'TM2019000024700010',
'TM2019000024700070',
'TM2019000024700080',
'Mr2019000000400010',
'TM2019000024700110',
'TM2019000024700100',
'TM2019000024700120',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Mj2019000000100010',
'Ma2019000003200020',
'Ma2019000000100020',
'TM2019000025700010',
'Mj2019000000400010',
'Mj2019000001000010',
'Mj2019000002000010',
'Ma2020000005000010',
'Mj2019000004800010',
'TM2019000026000010',
'TM2019000024700010',
'TM2019000024700110',
'TM2019000024700100',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'TM2019000024700120',
'TM2019000024700080',
'TM2019000026300010',
'TM2019000024700050',
'Mj2019000005400010',
'Mj2019000005400010',
'Mg2019000008700020',
'MB2020000006800120',
'Ma2020000001200020',
'Mj2019000023300040',
'Mj2019000006900010',
'Mj2019000007100010',
'TM2019000004500010',
'Mj2019000007400010',
'Mj2019000007000010',
'Mf2019000004700060',
'Mf2019000004700110',
'Ma2020000001200020',
'Mj2019000023300040',
'Mj2019000007200010',
'Mj2019000007200090',
'Mj2019000010100010',
'Mf2019000004700060',
'Mf2019000004700110',
'Mj2019000007400010',
'Mj2019000007000010',
'Ma2020000001200020',
'Mj2019000023300040',
'Mj2019000006400010',
'Mj2019000002600010',
'Mj2019000004600010',
'Mj2019000007700010',
'Mj2019000006500010',
'Mg2019000000200140',
'TM2019000026000010',
'TM2019000024700010',
'TM2019000024700110',
'TM2019000024700100',
'Mg2018000001600020',
'MB2018000000300020',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Mj2019000012000010',
'Mg2018000001600020',
'MB2019000010700020',
'TM2019000024700050',
'Mj2019000005400010',
'MB2020000006800120',
'Mg2019000022700040',
'Mj2019000000400010',
'Mj2019000023300040',
'Ma2020000001200020',
'Mg2019000016600260',
'Mf2019000004700060',
'Mf2019000004700110',
'Mg2019000018600170',
'Mj2019000011800010',
'Mj2019000007100010',
'Mg2019000013200020',
'Mj2019000006100010',
'Ma2019000001500020',
'Mg2018000000700020',
'Mj2019000013600010',
'Mj2019000010300010',
'Mg2018000001600020',
'Mf2019000004700020',
'Mj2019000002600010',
'Mg2019000000200140',
'Mj2019000023300040',
'Ma2020000001200020',
'Mf2019000004700060',
'Mf2019000004700110',
'Mj2019000013100010',
'Mg2019000008300020',
'Mj2019000010300010',
'Mg2019000002600040',
'Mg2019000025900020',
'Mj2019000013000010',
'Mg2018000001600020',
'Mg2018000001600020',
'Mg2019000000200140',
'Mv2020000001500010',
'Mj2019000010300010',
'Mg2018000001600020',
'Mf2019000003600020',
'Ma2020000001200020',
'Mf2019000004700060',
'Mf2019000004700110',
'Ma2019000000300020',
'TM2019000026300010',
'Mv2019000000100010',
'Mj2019000007100010',
'Mj2019000014100010',
'Mj2019000006500010',
'Mf2019000004700020',
'Mv2020000001500010',
'Ma2019000001800020',
'TM2019000026000010',
'MB2019000010700020',
'Mg2019000022700040',
'TM2019000024700110',
'TM2019000024700100',
'TM2019000024700050',
'Mj2019000005400010',
'TM2019000024700120',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Mg2019000000200140',
'TM2019000024700010',
'TM2019000025700010',
'Ma2019000000600020',
'Ma2019000000600020',
'Mf2019000003600020',
'Ma2020000001200020',
'Mf2019000004700060',
'Mf2019000004700110',
'Mj2019000014100010',
'Mv2020000001500010',
'Ma2019000001400020',
'Mf2019000004700020',
'Mv2020000001500010',
'Mg2018000001600020',
'Ma2019000002700020',
'Ma2020000000800020',
'Mv2019000000100010',
'Mg2019000018600170',
'Mg2019000016600260',
'Mg2019000000200140',
'Ma2019000002600020',
'Mj2020000001600010',
'Mv2020000001100010',
'Mj2019000001700010',
'Ma2019000003300020',
'TM2019000026300010',
'TM2019000025700010',
'Mg2019000008700020',
'TM2019000026300010',
'Mg2018000001600020',
'TM2019000024700010',
'Mj2020000012700010',
'PN2019000004900010',
'TM2019000024700110',
'TM2019000024700100',
'TM2019000024700050',
'PN2019000003700010',
'Ml2018000000300010',
'Mw2019000000100010',
'Mj2019000004700010',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Ma2020000000400020',
'Ma2020000004300010',
'Ma2020000004300010',
'Ma2019000003400020',
'TM2019000026300010',
'Ml2020000007500010',
'Ma2020000000400020',
'MB2019000037000020',
'Ma2020000000600020',
'Ma2020000005100010',
'Ma2020000005100010',
'Ma2020000000100020',
'Ma2020000000800020',
'TM2019000024700010',
'MB2019000037000020',
'TM2019000025200010',
'TM2019000024700110',
'TM2019000024700050',
'Ml2018000000300010',
'PN2019000003700010',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Mr2020000000400010',
'TM2019000024700100',
'PN2019000002400010',
'Mv2020000003100010',
'TM2019000025000010',
'Ma2020000000700020',
'Mv2020000000900010',
'Mv2020000000500010',
'Mv2020000000800010',
'Mv2020000000400010',
'Mv2020000000700010',
'Mb2020000001100010',
'Mw2020000001100010',
'Ma2020000001600020',
'Mw2020000001000010',
'TM2019000026300010',
'Mv2020000001100010',
'Ma2020000001200020',
'Mj2020000006800010',
'Ma2020000002100020',
'Mb2020000001400010',
'Ma2020000002000020',
'Mb2020000001300010',
'Ma2020000000700020',
'Mw2020000001200010',
'Ma2020000001600020',
'Mj2020000006800010',
'Mv2020000001100010',
'Mv2020000001100010',
'Ma2020000001200020',
'Mj2019000023300040',
'Ma2020000002300020',
'Ma2020000002300020',
'Mf2019000004700060',
'Ma2020000002500040',
'Mv2020000001500010',
'Mv2020000001500010',
'Mj2020000001200010',
'Mr2020000000100010',
'Mw2020000001500010',
'Ma2020000002000020',
'Ma2020000002000100',
'Mb2020000001500010',
'Ma2019000003600020',
'Mg2019000006000020',
'Ma2020000000900080',
'Mw2020000001600010',
'Mw2020000001600010',
'Mj2020000001200010',
'Ma2020000002300020',
'Mj2019000023300040',
'Ma2020000002400020',
'Ma2020000002500040',
'Ma2020000001200020',
'Mj2020000006800010',
'Ma2020000002100020',
'Mw2020000001700010',
'Ml2020000003300010',
'TM2019000024700100',
'TM2019000024700010',
'Mj2019000012400010',
'Ma2020000001600020',
'TM2019000024700110',
'TM2019000024700100',
'TM2019000024700050',
'Ma2020000001900020',
'Mj2019000005400010',
'Mv2019000000100010',
'Mr2019000000200010',
'Mr2020000000100010',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Mw2020000001800010',
'Mb2020000002000010',
'Mg2019000006000020',
'Mg2020000011900020',
'Ma2020000002000100',
'Ma2020000002000020',
'Ma2019000003600020',
'Ma2020000002300020',
'TM2020000002600010',
'Ma2020000002400020',
'Ma2020000002500040',
'Mv2020000001500010',
'Ma2020000003200010',
'Ma2020000002000020',
'Ma2020000002000100',
'Mr2020000000100010',
'Ma2019000003600020',
'Ma2020000002700020',
'Mv2020000001300010',
'Ma2020000001200020',
'Ma2020000001200020',
'Ma2020000002400020',
'Ma2020000002400020',
'Ma2020000002400020',
'Mv2020000001500010',
'Mv2020000002500010',
'Ma2020000002000020',
'Ma2020000002000100',
'Ma2020000003400010',
'Ma2020000003600010',
'Mv2020000002600010',
'Mv2020000002800010',
'Mv2020000003000010',
'Mv2020000002300010',
'Ma2020000002000020',
'Ma2020000002000100',
'Ma2020000003600010',
'Mv2020000002700010',
'TM2019000024700010',
'TM2019000024700100',
'Mg2019000022700040',
'Mr2020000000600010',
'TM2019000024700110',
'Mr2020000000400010',
'TM2019000024700050',
'Mj2019000005400010',
'Mv2019000000100010',
'Ma2020000001200020',
'Ma2020000001200020',
'Ma2020000002300020',
'Ma2020000002300020',
'Ma2020000002300020',
'Ma2020000004400040',
'Ma2020000004400040',
'TM2019000026000020',
'TM2019000024700040',
'TM2019000024700090',
'Mr2020000000300010',
'Ma2020000004600010',
'Mv2020000003300010',
'Mv2020000003200010',
'Ma2020000003900010',
'Ma2020000002000020',
'Ma2020000002000100',
'Ma2020000003600010',
'Mv2020000001500010',
'Mv2020000001500010',
'Ma2022000004200010',
'Ma2020000004400040',
'Ma2020000004400040',
'Ma2020000001200020',
'Ma2020000001200020',
'Ml2020000002700040',
'Ml2020000002700040',
'Ml2020000002700040',
'Ma2020000004700010',
'Ma2019000003600020',
'Mv2020000003700010',
'Mv2020000003600010',
'Ma2020000004100010',
'Mv2020000003800010',
'Mv2020000001500010',
'Mj2019000023300040',
'Ma2020000002300020',
'Mf2019000004700060',
'Ma2020000002500040',
'Ma2020000004800010',
'Mr2020000001200010',
'Ma2020000004300010',
'Mj2020000007400010',
'Mr2020000000900010',
'Ma2020000005100010',
'Mf2020000010700020',
'Ma2020000005200010',
'Ma2020000005000010',
'Ma2020000005500010',
'Ms2020000000600010',
'Ma2020000002000020',
'Ma2020000002000100',
'Mv2020000001500010',
'Ma2020000005700010',
'Mr2020000000700010',
'Ma2020000005600010',
'Ma2020000005500010',
'Ma2021000000100010',
'Ma2019000003600020',
'Ma2020000002000020',
'Ma2020000002000100',
'Ms2020000000600010',
'Ma2021000000300010',
'Ma2021000000500010',
'Mv2021000000200010',
'Ma2021000000800010',
'Ma2019000003600020',
'Ms2020000000600010',
'Ma2021000000900010',
'Mv2021000000700010',
'TM2019000026300010',
'Ma2019000003600020',
'Mv2020000001100010',
'Mv2021000000500010',
'Ma2021000001500010',
'Ma2021000001400010',
'Mr2020000000700010',
'Mr2021000000100010',
'Mj2019000012400010',
'Mr2020000000600010',
'Mr2020000000400010',
'Mv2019000000100010',
'Mr2019000000200010',
'Mr2020000000300010',
'Mr2020000000300010',
'Ms2020000000600010',
'Mj2021000005100010',
'Mr2021000000500010',
'Ma2019000003600020',
'Mv2020000002500010',
'Mg2020000035400020',
'Ms2020000000600010',
'Ma2019000003600020',
'Mv2020000002900010',
'Mv2021000001100010',
'Ma2021000002000010',
'Ma2021000001900010',
'TM2020000002600010',
'Ma2020000002300020',
'Ma2020000002500040',
'Ma2020000002400020',
'Ma2021000002200010',
'Ma2021000002300010',
'Ma2021000002500010',
'Ma2019000000100020',
'Mv2021000000700010',
'Mv2021000001100010',
'TM2020000002600010',
'Ma2020000002400020',
'Ma2020000002500040',
'Mv2020000002900010',
'Ma2021000002300010',
'Ma2021000002600010',
'Mr2020000000700010',
'Mr2021000000100010',
'Mj2019000012400010',
'Mr2020000001100010',
'TM2020000003400010',
'Mj2021000005400010',
'Mv2019000000100010',
'Mr2019000000200010',
'Mv2021000001100010',
'TM2020000002600010',
'Ma2020000002400020',
'Ma2020000002500040',
'Mv2020000002900010',
'Ma2021000002200010',
'Ma2021000002300010',
'Ma2021000002600010',
'Mr2020000001200010',
'Ma2021000001200010',
'Ma2021000001200010',
'Mr2021000000500010',
'Ma2021000001800010',
'Ma2021000003600010',
'Mv2020000001100010',
'Ma2021000002200010',
'TM2020000002600010',
'Mj2019000023300010',
'Mj2019000023300020',
'Ma2021000002400010',
'Ma2021000002300010',
'Ma2020000002300020',
'Ma2021000001800010',
'Ma2021000003900010',
'Ma2021000003100010',
'Ma2021000003300010',
'Ma2021000003800010',
'Ma2021000003200010',
'Ma2021000002100010',
'Ma2021000002100010',
'Mv2021000001400010',
'Ma2021000002500010',
'Mv2021000001300010',
'Ma2021000003900010',
'Ma2021000001800010',
'Ma2021000003200010',
'Ma2021000003100010',
'Ma2021000002400010',
'Ma2021000003300010',
'Ms2020000000600010',
'Mv2021000001100010',
'Mv2021000001100010',
'Mv2020000001100010',
'Ma2021000002200010',
'Mj2019000023300040',
'Ma2020000002400020',
'Ma2020000002500040',
'Ma2021000002300010',
'Ma2020000002300020',
'Mr2021000000500010',
'Mr2020000000700010',
'TM2020000003400010',
'Ma2021000003300010',
'Ma2021000003100010',
'Ma2021000003900010',
'Ma2021000001800010',
'Ma2021000003200010',
'Ma2021000002300010',
'Ma2021000002400010',
'TM2020000002600010',
'Ma2021000002200010',
'Mv2021000001100010',
'Mv2020000001100010',
'Ms2020000000600010',
'Ma2021000004100010',
'Mv2020000001100010',
'Ma2021000002400010',
'Ma2021000001800010',
'Ma2021000004600010',
'Mf2019000006600020',
'Ma2021000004300010',
'Ma2021000001800010',
'Ma2021000002400010',
'Mv2021000001100010',
'Mj2021000005200010',
'Mr2021000000400010',
'Mj2019000005400010',
'Mr2020000000700010',
'Mr2021000000100010',
'Mj2019000012400010',
'TM2020000003200010',
'TM2020000003400010',
'Mv2019000000100010',
'Mr2019000000200010',
'TM2020000003300010',
'Ma2021000001800010',
'Ma2021000002400010',
'Mv2021000001000010',
'Mv2020000001100010',
'TM2019000026300010',
'Ma2021000004500010',
'Mv2020000001100010',
'Ma2021000002400010',
'Ma2021000001800010',
'Mj2021000016300010',
'Ma2022000000200010',
'Ma2022000000400010',
'Ma2022000000100010',
'Ma2022000001100010',
'Mv2022000000200010',
'Ma2022000001300010',
'TM2022000009400010',
'Mv2021000000900010',
'Mv2022000000100010',
'Ma2022000000500010',
'Ma2022000001100080',
'Ma2021000002400010',
'Ma2021000001800010',
'Mv2022000000300010',
'Mv2022000000400010',
'Mv2021000001000010',
'Ma2020000003000020',
'Ma2021000002500010',
'Ma2021000002400010',
'Mj2022000001400010',
'Mv2022000000400010',
'Mv2021000001000010',
'Ma2021000002400010',
'Ma2022000001500010',
'Ma2021000001800010',
'Ma2022000002200010',
'Ms2020000000600010',
'Ma2021000002300010',
'Ma2022000003200010',
'Ma2022000002800010',
'Mj2019000005400010',
'Mr2020000000700010',
'Mv2021000001000010',
'Ma2021000001800010',
'Mj2021000016300010',
'Mv2021000001000010',
'Ma2021000002400010',
'Ma2021000002500010',
'Ma2021000002300010',
'Ma2022000003200010',
'Ma2021000002300010',
'Mv2022000000400010',
'Mv2021000001000010',
'Ma2021000002400010',
'Ma2021000002500010',
'Ma2021000004800010',
'Ma2022000004100010',
'Mv2022000000400010',
'Mv2021000001000010',
'Ma2021000002400010',
'Ma2022000004100010',
'Ma2022000004200010',
'Ma2021000001800010',
'Ma2022000002700010',
'Ma2022000004000010',
'Ma2021000002300010',
'Ma2021000004800010',
'Mb2022000003000010',
'Mb2022000002900010',
'Ma2021000002500010',
'Ma2022000002900010',
'Mj2019000005400010',
'Mr2021000000100010',
'Mr2020000000700010',
'Mr2021000000500010',
'Mb2022000003200010',
'Mv2022000000400010',
'Mv2021000001000010',
'Mw2022000001000010',
'Ma2022000004300010',
'Ma2021000002500010',
'Mw2022000001100010',
'Mv2022000001200010',
'Mb2022000003400010',
'Mb2022000003500010')
I tried using ORDER BY statement but with no effects I'd like to obtain.
Try this:
WITH dat AS
(
SELECT 'TM2019000026000010' AS val FROM dual UNION ALL
SELECT 'TM2019000024700010' FROM dual UNION ALL
...
SELECT 'Mj2019000023300040' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Mf2019000004700060' FROM dual UNION ALL
SELECT 'Mf2019000004700110' FROM dual UNION ALL
SELECT 'Mj2019000013100010' FROM dual UNION ALL
SELECT 'Mg2019000008300020' FROM dual UNION ALL
SELECT 'Mj2019000010300010' FROM dual UNION ALL
SELECT 'Mg2019000002600040' FROM dual UNION ALL
SELECT 'Mg2019000025900020' FROM dual UNION ALL
SELECT 'Mj2019000013000010' FROM dual UNION ALL
SELECT 'Mg2018000001600020' FROM dual UNION ALL
SELECT 'Mg2018000001600020' FROM dual UNION ALL
SELECT 'Mg2019000000200140' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mj2019000010300010' FROM dual UNION ALL
SELECT 'Mg2018000001600020' FROM dual UNION ALL
SELECT 'Mf2019000003600020' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Mf2019000004700060' FROM dual UNION ALL
SELECT 'Mf2019000004700110' FROM dual UNION ALL
SELECT 'Ma2019000000300020' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Mj2019000007100010' FROM dual UNION ALL
SELECT 'Mj2019000014100010' FROM dual UNION ALL
SELECT 'Mj2019000006500010' FROM dual UNION ALL
SELECT 'Mf2019000004700020' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Ma2019000001800020' FROM dual UNION ALL
SELECT 'TM2019000026000010' FROM dual UNION ALL
SELECT 'MB2019000010700020' FROM dual UNION ALL
SELECT 'Mg2019000022700040' FROM dual UNION ALL
SELECT 'TM2019000024700110' FROM dual UNION ALL
SELECT 'TM2019000024700100' FROM dual UNION ALL
SELECT 'TM2019000024700050' FROM dual UNION ALL
SELECT 'Mj2019000005400010' FROM dual UNION ALL
SELECT 'TM2019000024700120' FROM dual UNION ALL
SELECT 'TM2019000026000020' FROM dual UNION ALL
SELECT 'TM2019000024700040' FROM dual UNION ALL
SELECT 'TM2019000024700090' FROM dual UNION ALL
SELECT 'Mg2019000000200140' FROM dual UNION ALL
SELECT 'TM2019000024700010' FROM dual UNION ALL
SELECT 'TM2019000025700010' FROM dual UNION ALL
SELECT 'Ma2019000000600020' FROM dual UNION ALL
SELECT 'Ma2019000000600020' FROM dual UNION ALL
SELECT 'Mf2019000003600020' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Mf2019000004700060' FROM dual UNION ALL
SELECT 'Mf2019000004700110' FROM dual UNION ALL
SELECT 'Mj2019000014100010' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Ma2019000001400020' FROM dual UNION ALL
SELECT 'Mf2019000004700020' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mg2018000001600020' FROM dual UNION ALL
SELECT 'Ma2019000002700020' FROM dual UNION ALL
SELECT 'Ma2020000000800020' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Mg2019000018600170' FROM dual UNION ALL
SELECT 'Mg2019000016600260' FROM dual UNION ALL
SELECT 'Mg2019000000200140' FROM dual UNION ALL
SELECT 'Ma2019000002600020' FROM dual UNION ALL
SELECT 'Mj2020000001600010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Mj2019000001700010' FROM dual UNION ALL
SELECT 'Ma2019000003300020' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'TM2019000025700010' FROM dual UNION ALL
SELECT 'Mg2019000008700020' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'Mg2018000001600020' FROM dual UNION ALL
SELECT 'TM2019000024700010' FROM dual UNION ALL
SELECT 'Mj2020000012700010' FROM dual UNION ALL
SELECT 'PN2019000004900010' FROM dual UNION ALL
SELECT 'TM2019000024700110' FROM dual UNION ALL
SELECT 'TM2019000024700100' FROM dual UNION ALL
SELECT 'TM2019000024700050' FROM dual UNION ALL
SELECT 'PN2019000003700010' FROM dual UNION ALL
SELECT 'Ml2018000000300010' FROM dual UNION ALL
SELECT 'Mw2019000000100010' FROM dual UNION ALL
SELECT 'Mj2019000004700010' FROM dual UNION ALL
SELECT 'TM2019000026000020' FROM dual UNION ALL
SELECT 'TM2019000024700040' FROM dual UNION ALL
SELECT 'TM2019000024700090' FROM dual UNION ALL
SELECT 'Ma2020000000400020' FROM dual UNION ALL
SELECT 'Ma2020000004300010' FROM dual UNION ALL
SELECT 'Ma2020000004300010' FROM dual UNION ALL
SELECT 'Ma2019000003400020' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'Ml2020000007500010' FROM dual UNION ALL
SELECT 'Ma2020000000400020' FROM dual UNION ALL
SELECT 'MB2019000037000020' FROM dual UNION ALL
SELECT 'Ma2020000000600020' FROM dual UNION ALL
SELECT 'Ma2020000005100010' FROM dual UNION ALL
SELECT 'Ma2020000005100010' FROM dual UNION ALL
SELECT 'Ma2020000000100020' FROM dual UNION ALL
SELECT 'Ma2020000000800020' FROM dual UNION ALL
SELECT 'TM2019000024700010' FROM dual UNION ALL
SELECT 'MB2019000037000020' FROM dual UNION ALL
SELECT 'TM2019000025200010' FROM dual UNION ALL
SELECT 'TM2019000024700110' FROM dual UNION ALL
SELECT 'TM2019000024700050' FROM dual UNION ALL
SELECT 'Ml2018000000300010' FROM dual UNION ALL
SELECT 'PN2019000003700010' FROM dual UNION ALL
SELECT 'TM2019000026000020' FROM dual UNION ALL
SELECT 'TM2019000024700040' FROM dual UNION ALL
SELECT 'TM2019000024700090' FROM dual UNION ALL
SELECT 'Mr2020000000400010' FROM dual UNION ALL
SELECT 'TM2019000024700100' FROM dual UNION ALL
SELECT 'PN2019000002400010' FROM dual UNION ALL
SELECT 'Mv2020000003100010' FROM dual UNION ALL
SELECT 'TM2019000025000010' FROM dual UNION ALL
SELECT 'Ma2020000000700020' FROM dual UNION ALL
SELECT 'Mv2020000000900010' FROM dual UNION ALL
SELECT 'Mv2020000000500010' FROM dual UNION ALL
SELECT 'Mv2020000000800010' FROM dual UNION ALL
SELECT 'Mv2020000000400010' FROM dual UNION ALL
SELECT 'Mv2020000000700010' FROM dual UNION ALL
SELECT 'Mb2020000001100010' FROM dual UNION ALL
SELECT 'Mw2020000001100010' FROM dual UNION ALL
SELECT 'Ma2020000001600020' FROM dual UNION ALL
SELECT 'Mw2020000001000010' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Mj2020000006800010' FROM dual UNION ALL
SELECT 'Ma2020000002100020' FROM dual UNION ALL
SELECT 'Mb2020000001400010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Mb2020000001300010' FROM dual UNION ALL
SELECT 'Ma2020000000700020' FROM dual UNION ALL
SELECT 'Mw2020000001200010' FROM dual UNION ALL
SELECT 'Ma2020000001600020' FROM dual UNION ALL
SELECT 'Mj2020000006800010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Mj2019000023300040' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Mf2019000004700060' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mj2020000001200010' FROM dual UNION ALL
SELECT 'Mr2020000000100010' FROM dual UNION ALL
SELECT 'Mw2020000001500010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Mb2020000001500010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Mg2019000006000020' FROM dual UNION ALL
SELECT 'Ma2020000000900080' FROM dual UNION ALL
SELECT 'Mw2020000001600010' FROM dual UNION ALL
SELECT 'Mw2020000001600010' FROM dual UNION ALL
SELECT 'Mj2020000001200010' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Mj2019000023300040' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Mj2020000006800010' FROM dual UNION ALL
SELECT 'Ma2020000002100020' FROM dual UNION ALL
SELECT 'Mw2020000001700010' FROM dual UNION ALL
SELECT 'Ml2020000003300010' FROM dual UNION ALL
SELECT 'TM2019000024700100' FROM dual UNION ALL
SELECT 'TM2019000024700010' FROM dual UNION ALL
SELECT 'Mj2019000012400010' FROM dual UNION ALL
SELECT 'Ma2020000001600020' FROM dual UNION ALL
SELECT 'TM2019000024700110' FROM dual UNION ALL
SELECT 'TM2019000024700100' FROM dual UNION ALL
SELECT 'TM2019000024700050' FROM dual UNION ALL
SELECT 'Ma2020000001900020' FROM dual UNION ALL
SELECT 'Mj2019000005400010' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Mr2019000000200010' FROM dual UNION ALL
SELECT 'Mr2020000000100010' FROM dual UNION ALL
SELECT 'TM2019000026000020' FROM dual UNION ALL
SELECT 'TM2019000024700040' FROM dual UNION ALL
SELECT 'TM2019000024700090' FROM dual UNION ALL
SELECT 'Mw2020000001800010' FROM dual UNION ALL
SELECT 'Mb2020000002000010' FROM dual UNION ALL
SELECT 'Mg2019000006000020' FROM dual UNION ALL
SELECT 'Mg2020000011900020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'TM2020000002600010' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Ma2020000003200010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Mr2020000000100010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Ma2020000002700020' FROM dual UNION ALL
SELECT 'Mv2020000001300010' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mv2020000002500010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Ma2020000003400010' FROM dual UNION ALL
SELECT 'Ma2020000003600010' FROM dual UNION ALL
SELECT 'Mv2020000002600010' FROM dual UNION ALL
SELECT 'Mv2020000002800010' FROM dual UNION ALL
SELECT 'Mv2020000003000010' FROM dual UNION ALL
SELECT 'Mv2020000002300010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Ma2020000003600010' FROM dual UNION ALL
SELECT 'Mv2020000002700010' FROM dual UNION ALL
SELECT 'TM2019000024700010' FROM dual UNION ALL
SELECT 'TM2019000024700100' FROM dual UNION ALL
SELECT 'Mg2019000022700040' FROM dual UNION ALL
SELECT 'Mr2020000000600010' FROM dual UNION ALL
SELECT 'TM2019000024700110' FROM dual UNION ALL
SELECT 'Mr2020000000400010' FROM dual UNION ALL
SELECT 'TM2019000024700050' FROM dual UNION ALL
SELECT 'Mj2019000005400010' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Ma2020000004400040' FROM dual UNION ALL
SELECT 'Ma2020000004400040' FROM dual UNION ALL
SELECT 'TM2019000026000020' FROM dual UNION ALL
SELECT 'TM2019000024700040' FROM dual UNION ALL
SELECT 'TM2019000024700090' FROM dual UNION ALL
SELECT 'Mr2020000000300010' FROM dual UNION ALL
SELECT 'Ma2020000004600010' FROM dual UNION ALL
SELECT 'Mv2020000003300010' FROM dual UNION ALL
SELECT 'Mv2020000003200010' FROM dual UNION ALL
SELECT 'Ma2020000003900010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Ma2020000003600010' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Ma2022000004200010' FROM dual UNION ALL
SELECT 'Ma2020000004400040' FROM dual UNION ALL
SELECT 'Ma2020000004400040' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Ma2020000001200020' FROM dual UNION ALL
SELECT 'Ml2020000002700040' FROM dual UNION ALL
SELECT 'Ml2020000002700040' FROM dual UNION ALL
SELECT 'Ml2020000002700040' FROM dual UNION ALL
SELECT 'Ma2020000004700010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Mv2020000003700010' FROM dual UNION ALL
SELECT 'Mv2020000003600010' FROM dual UNION ALL
SELECT 'Ma2020000004100010' FROM dual UNION ALL
SELECT 'Mv2020000003800010' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Mj2019000023300040' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Mf2019000004700060' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Ma2020000004800010' FROM dual UNION ALL
SELECT 'Mr2020000001200010' FROM dual UNION ALL
SELECT 'Ma2020000004300010' FROM dual UNION ALL
SELECT 'Mj2020000007400010' FROM dual UNION ALL
SELECT 'Mr2020000000900010' FROM dual UNION ALL
SELECT 'Ma2020000005100010' FROM dual UNION ALL
SELECT 'Mf2020000010700020' FROM dual UNION ALL
SELECT 'Ma2020000005200010' FROM dual UNION ALL
SELECT 'Ma2020000005000010' FROM dual UNION ALL
SELECT 'Ma2020000005500010' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Mv2020000001500010' FROM dual UNION ALL
SELECT 'Ma2020000005700010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'Ma2020000005600010' FROM dual UNION ALL
SELECT 'Ma2020000005500010' FROM dual UNION ALL
SELECT 'Ma2021000000100010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Ma2020000002000020' FROM dual UNION ALL
SELECT 'Ma2020000002000100' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Ma2021000000300010' FROM dual UNION ALL
SELECT 'Ma2021000000500010' FROM dual UNION ALL
SELECT 'Mv2021000000200010' FROM dual UNION ALL
SELECT 'Ma2021000000800010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Ma2021000000900010' FROM dual UNION ALL
SELECT 'Mv2021000000700010' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Mv2021000000500010' FROM dual UNION ALL
SELECT 'Ma2021000001500010' FROM dual UNION ALL
SELECT 'Ma2021000001400010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'Mr2021000000100010' FROM dual UNION ALL
SELECT 'Mj2019000012400010' FROM dual UNION ALL
SELECT 'Mr2020000000600010' FROM dual UNION ALL
SELECT 'Mr2020000000400010' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Mr2019000000200010' FROM dual UNION ALL
SELECT 'Mr2020000000300010' FROM dual UNION ALL
SELECT 'Mr2020000000300010' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Mj2021000005100010' FROM dual UNION ALL
SELECT 'Mr2021000000500010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Mv2020000002500010' FROM dual UNION ALL
SELECT 'Mg2020000035400020' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Ma2019000003600020' FROM dual UNION ALL
SELECT 'Mv2020000002900010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'Ma2021000002000010' FROM dual UNION ALL
SELECT 'Ma2021000001900010' FROM dual UNION ALL
SELECT 'TM2020000002600010' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2021000002200010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Ma2019000000100020' FROM dual UNION ALL
SELECT 'Mv2021000000700010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'TM2020000002600010' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Mv2020000002900010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2021000002600010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'Mr2021000000100010' FROM dual UNION ALL
SELECT 'Mj2019000012400010' FROM dual UNION ALL
SELECT 'Mr2020000001100010' FROM dual UNION ALL
SELECT 'TM2020000003400010' FROM dual UNION ALL
SELECT 'Mj2021000005400010' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Mr2019000000200010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'TM2020000002600010' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Mv2020000002900010' FROM dual UNION ALL
SELECT 'Ma2021000002200010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2021000002600010' FROM dual UNION ALL
SELECT 'Mr2020000001200010' FROM dual UNION ALL
SELECT 'Ma2021000001200010' FROM dual UNION ALL
SELECT 'Ma2021000001200010' FROM dual UNION ALL
SELECT 'Mr2021000000500010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000003600010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ma2021000002200010' FROM dual UNION ALL
SELECT 'TM2020000002600010' FROM dual UNION ALL
SELECT 'Mj2019000023300010' FROM dual UNION ALL
SELECT 'Mj2019000023300020' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000003900010' FROM dual UNION ALL
SELECT 'Ma2021000003100010' FROM dual UNION ALL
SELECT 'Ma2021000003300010' FROM dual UNION ALL
SELECT 'Ma2021000003800010' FROM dual UNION ALL
SELECT 'Ma2021000003200010' FROM dual UNION ALL
SELECT 'Ma2021000002100010' FROM dual UNION ALL
SELECT 'Ma2021000002100010' FROM dual UNION ALL
SELECT 'Mv2021000001400010' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Mv2021000001300010' FROM dual UNION ALL
SELECT 'Ma2021000003900010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000003200010' FROM dual UNION ALL
SELECT 'Ma2021000003100010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000003300010' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ma2021000002200010' FROM dual UNION ALL
SELECT 'Mj2019000023300040' FROM dual UNION ALL
SELECT 'Ma2020000002400020' FROM dual UNION ALL
SELECT 'Ma2020000002500040' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2020000002300020' FROM dual UNION ALL
SELECT 'Mr2021000000500010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'TM2020000003400010' FROM dual UNION ALL
SELECT 'Ma2021000003300010' FROM dual UNION ALL
SELECT 'Ma2021000003100010' FROM dual UNION ALL
SELECT 'Ma2021000003900010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000003200010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'TM2020000002600010' FROM dual UNION ALL
SELECT 'Ma2021000002200010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Ma2021000004100010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000004600010' FROM dual UNION ALL
SELECT 'Mf2019000006600020' FROM dual UNION ALL
SELECT 'Ma2021000004300010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Mv2021000001100010' FROM dual UNION ALL
SELECT 'Mj2021000005200010' FROM dual UNION ALL
SELECT 'Mr2021000000400010' FROM dual UNION ALL
SELECT 'Mj2019000005400010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'Mr2021000000100010' FROM dual UNION ALL
SELECT 'Mj2019000012400010' FROM dual UNION ALL
SELECT 'TM2020000003200010' FROM dual UNION ALL
SELECT 'TM2020000003400010' FROM dual UNION ALL
SELECT 'Mv2019000000100010' FROM dual UNION ALL
SELECT 'Mr2019000000200010' FROM dual UNION ALL
SELECT 'TM2020000003300010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'TM2019000026300010' FROM dual UNION ALL
SELECT 'Ma2021000004500010' FROM dual UNION ALL
SELECT 'Mv2020000001100010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Mj2021000016300010' FROM dual UNION ALL
SELECT 'Ma2022000000200010' FROM dual UNION ALL
SELECT 'Ma2022000000400010' FROM dual UNION ALL
SELECT 'Ma2022000000100010' FROM dual UNION ALL
SELECT 'Ma2022000001100010' FROM dual UNION ALL
SELECT 'Mv2022000000200010' FROM dual UNION ALL
SELECT 'Ma2022000001300010' FROM dual UNION ALL
SELECT 'TM2022000009400010' FROM dual UNION ALL
SELECT 'Mv2021000000900010' FROM dual UNION ALL
SELECT 'Mv2022000000100010' FROM dual UNION ALL
SELECT 'Ma2022000000500010' FROM dual UNION ALL
SELECT 'Ma2022000001100080' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Mv2022000000300010' FROM dual UNION ALL
SELECT 'Mv2022000000400010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Ma2020000003000020' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Mj2022000001400010' FROM dual UNION ALL
SELECT 'Mv2022000000400010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2022000001500010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2022000002200010' FROM dual UNION ALL
SELECT 'Ms2020000000600010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2022000003200010' FROM dual UNION ALL
SELECT 'Ma2022000002800010' FROM dual UNION ALL
SELECT 'Mj2019000005400010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Mj2021000016300010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2022000003200010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Mv2022000000400010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Ma2021000004800010' FROM dual UNION ALL
SELECT 'Ma2022000004100010' FROM dual UNION ALL
SELECT 'Mv2022000000400010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Ma2021000002400010' FROM dual UNION ALL
SELECT 'Ma2022000004100010' FROM dual UNION ALL
SELECT 'Ma2022000004200010' FROM dual UNION ALL
SELECT 'Ma2021000001800010' FROM dual UNION ALL
SELECT 'Ma2022000002700010' FROM dual UNION ALL
SELECT 'Ma2022000004000010' FROM dual UNION ALL
SELECT 'Ma2021000002300010' FROM dual UNION ALL
SELECT 'Ma2021000004800010' FROM dual UNION ALL
SELECT 'Mb2022000003000010' FROM dual UNION ALL
SELECT 'Mb2022000002900010' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Ma2022000002900010' FROM dual UNION ALL
SELECT 'Mj2019000005400010' FROM dual UNION ALL
SELECT 'Mr2021000000100010' FROM dual UNION ALL
SELECT 'Mr2020000000700010' FROM dual UNION ALL
SELECT 'Mr2021000000500010' FROM dual UNION ALL
SELECT 'Mb2022000003200010' FROM dual UNION ALL
SELECT 'Mv2022000000400010' FROM dual UNION ALL
SELECT 'Mv2021000001000010' FROM dual UNION ALL
SELECT 'Mw2022000001000010' FROM dual UNION ALL
SELECT 'Ma2022000004300010' FROM dual UNION ALL
SELECT 'Ma2021000002500010' FROM dual UNION ALL
SELECT 'Mw2022000001100010' FROM dual UNION ALL
SELECT 'Mv2022000001200010' FROM dual UNION ALL
SELECT 'Mb2022000003400010' FROM dual UNION ALL
SELECT 'Mb2022000003500010' FROM dual
)
SELECT bol.*
FROM BOLLER1 bol
, (SELECT val, ROWNUM AS rn
FROM dat) kt
WHERE bol.BOLR1_KT1 = kt.val
ORDER BY kt.rn;
EDIT: removed some of the rows so that the answer fits the size limits, however the principle is the same
I would write the list as a collection. This is similar to the accepted answer, but avoids a lot of verbose select from dual union alls.
Setup:
create table boller1 (bolr1_kt1 varchar2(30));
insert all
into boller1 values ('Kitten')
into boller1 values ('Mr2019000000400010')
into boller1 values ('TM2019000024700100')
into boller1 values ('TM2019000024700120')
into boller1 values ('TM9019000024700080')
into boller1 values ('Xenomorph')
select * from dual;
Query:
with kits (seq, kit) as (
select rownum, column_value
from sys.dbms_debug_vc2coll('Xenomorph', 'Kitten', 'Mr2019000000400010', 'TM2019000024700100')
)
select b.bolr1_kt1
from boller1 b
join kits k on k.kit = b.bolr1_kt1
order by k.seq;
BOLR1_KT1
------------------------------
Xenomorph
Kitten
Mr2019000000400010
TM2019000024700100
You can use any scalar varchar2 collection type you already have, or create one with something like
create or replace type short_string_ntt as table of varchar2(50)
I just used the predefined sys.dbms_debug_vc2coll for demo convenience.

How to join table with result column in oracle

I used case when to get a column named 'code' in oracle. Now I want to get another column from a table which need to be joined with the result 'code' column.
Example:
select
(case when field='A' then '001'
when field='B' then '002'
end) code
from table_code
Now I want to get another column 'code_name' in this query from table 'names' containing data as
code: 001= code_name: aa & code: 002= code_name: bb
WITH clause is here just to generate some sample data, and as such, it is not a part of the answer.
Just guessing what you are asking for, but if I got it right the answer is below.
First the sample data:
WITH
ids_data AS
(
Select 'A' "CODE_ID", 'ABCD_123' "SOME_FLD", 10 "AMOUNT" From Dual Union All
Select 'B' "CODE_ID", 'BCD_123' "SOME_FLD", 25 "AMOUNT" From Dual Union All
Select 'C' "CODE_ID", 'CD_123' "SOME_FLD", 10 "AMOUNT" From Dual Union All
Select 'D' "CODE_ID", 'D_123' "SOME_FLD", 30 "AMOUNT" From Dual Union All
Select 'E' "CODE_ID", 'X123' "SOME_FLD", 15 "AMOUNT" From Dual U
),
names_data AS
(
Select '001' "CODE_ID", 'Code Name 001' "CODE_NAME" From Dual Union All
Select '002' "CODE_ID", 'Code Name 002' "CODE_NAME" From Dual Union All
Select '003' "CODE_ID", 'Code Name 003' "CODE_NAME" From Dual Union All
Select '004' "CODE_ID", 'Code Name 004' "CODE_NAME" From Dual Union All
Select '005' "CODE_ID", 'Code Name 005' "CODE_NAME" From Dual U
)
The answer is - just use the CASE statement in the join condition ON clause like you did it in the select clause.
SELECT
i.CODE_ID "CODE_ID",
CASE
WHEN i.CODE_ID = 'A' THEN '001'
WHEN i.CODE_ID = 'B' THEN '002'
WHEN i.CODE_ID = 'C' THEN '003'
WHEN i.CODE_ID = 'D' THEN '004'
WHEN i.CODE_ID = 'E' THEN '005'
ELSE
'000'
END "CODE_ID_2",
n.CODE_NAME "CODE_NAME",
i.SOME_FLD "SOME_FFLD",
i.AMOUNT "AMOUNT"
FROM
ids_data i
INNER JOIN
names_data n
ON(n.CODE_ID = CASE
WHEN i.CODE_ID = 'A' THEN '001'
WHEN i.CODE_ID = 'B' THEN '002'
WHEN i.CODE_ID = 'C' THEN '003'
WHEN i.CODE_ID = 'D' THEN '004'
WHEN i.CODE_ID = 'E' THEN '005'
ELSE
'000'
END)
Here is the result
--
-- R e s u l t :
--
-- CODE_ID CODE_ID_2 CODE_NAME SOME_FFLD AMOUNT
-- ------- --------- ------------- --------- ----------
-- A 001 Code Name 001 ABCD_123 10
-- B 002 Code Name 002 BCD_123 25
-- C 003 Code Name 003 CD_123 10
-- D 004 Code Name 004 D_123 30
-- E 005 Code Name 005 X123 15

I need the count of values

I have data in my table in oracle like below
A_CODE B_M P_id
------ ---- ------
123 A 1
123 A 2
123 B 5
678 B 3
678 C 3
678 B 4
123 BC 2
The value "BC" is B and C. The data is not normalized so we need to count it as B and C. I need the counts to be displayed as below per A_CODE
A_CODE B_M COUNT
------- ---- -------
123 A 2
123 B 2
123 C 1
678 B 2
678 C 1
How can i do this in Oracle?
You should use CONNECT BY and CONNECT_BY_ROOT.
I hope this helps:
SELECT A_CODE, B_M, COUNT (*)
FROM ( SELECT A_CODE, SUBSTR (CONNECT_BY_ROOT (B_M), LEVEL, 1) B_M
FROM your_table
CONNECT BY LEVEL <= LENGTH (B_M))
WHERE B_M IS NOT NULL
GROUP BY A_CODE, B_M
ORDER BY A_CODE;
Please try below:
SELECT A_CODE, B_M, COUNT(*) "COUNT" FROM
(SELECT A_CODE, B_M
FROM
(SELECT A_CODE,
SUBSTR(B_M,x.LVL,1) B_M
FROM my_table t,
(SELECT LEVEL LVL FROM dual
CONNECT BY LEVEL <=
(SELECT MAX(LENGTH(B_M)) FROM my_table)
) x
WHERE t.B_M is not null
)
WHERE B_M IS NOT NULL
UNION ALL
SELECT A_CODE, B_M FROM my_table WHERE B_M IS NULL
)
GROUP BY A_CODE,
B_M
ORDER BY A_CODE, B_M;
One option is to join this table to a data set that provides you with the normalised structure you need.
with cte_normaliser as (
select 'A' B_M, 'A' 'B_M_norm from dual union all
select 'B' B_M, 'B' 'B_M_norm from dual union all
select 'C' B_M, 'C' 'B_M_norm from dual union all
select 'BC' B_M, 'B' 'B_M_norm from dual union all
select 'BC' B_M, 'C' 'B_M_norm from dual)
select my_table.A_CODE,
n.B_M_norm,
count(*)
from my_table join
cte_normaliser n on n.B_M = my_table.B_M
group by my_table.A_CODE,
n.B_M_norm;
Using a fixed data set like that might not be feasible if you have a large number of variable code combination, though, and that data set might need to be built dynamically.
Besides having my_table, you create a table with all possible values. That is:
P_VAL
-----
A
B
C
Then, you should be able to obtain the count of occurrences with a join. Something like:
with my_table
as ( select '123' a_code, 'A' b_m, '1' p_id from dual
union select '123' a_code, 'A' b_m, '2' p_id from dual
union select '123' a_code, 'B' b_m, '5' p_id from dual
union select '678' a_code, 'B' b_m, '3' p_id from dual
union select '678' a_code, 'C' b_m, '3' p_id from dual
union select '678' a_code, 'B' b_m, '4' p_id from dual
union select '123' a_code, 'BC' b_m, '2' p_id from dual)
,possible_values
as ( select 'A' p_val from dual
union select 'B' p_val from dual
union select 'C' p_val from dual)
select a_code
,p_val b_m
,count('X') count
from my_table
join possible_values
on instr(b_m,p_val) > 0
group by a_code,p_val
order by a_code,p_val;

How to use analytic count to conditionally count?

Using this example, how can I tweak my sql to report whether a listing_id has passed all the tests?
with listing_row
as
(
select 1 as listing_id, 'TEST1' as listing_test, 'Y' as pass_yn from dual union all
select 1 as listing_id, 'TEST2' as listing_test, 'Y' as pass_yn from dual union all
select 1 as listing_id, 'TEST3' as listing_test, 'Y' as pass_yn from dual union all
select 2 as listing_id, 'TEST1' as listing_test, 'N' as pass_yn from dual union all
select 2 as listing_id, 'TEST2' as listing_test, 'Y' as pass_yn from dual union all
select 2 as listing_id, 'TEST3' as listing_test, 'N' as pass_yn from dual union all
select 3 as listing_id, 'TEST1' as listing_test, 'N' as pass_yn from dual union all
select 3 as listing_id, 'TEST2' as listing_test, 'N' as pass_yn from dual union all
select 3 as listing_id, 'TEST3' as listing_test, 'N' as pass_yn from dual)
select listing_id,
listing_test,pass_yn,
count(*) over (partition by listing_id, pass_yn) as all_y,
count(*) over (partition by listing_id, pass_yn) as all_n
from listing_row
Desired Results
LISTING_ID ALL_Y ALL_N
1 Y N
2 N N
3 N Y
I think the easiest way is to use min() and max():
select listing_id,
listing_test, pass_yn,
min(pass_yn) over (partition by listing_id) as all_y,
min(case when pass_yn = 'Y' then 'N' else 'Y' end) over (partition by listing_id) as all_n
from listing_row;
This uses a trick based on the fact the "Y" > "N". So, if you take the min() of the column and it has any "N" values, then the result will be "N".
This is another solution using sum():
SELECT listing_id,
CASE WHEN max(all_test_cnt)-MAX(num_of_test) = 0 THEN 'Y' ELSE 'N' END all_y,
CASE WHEN MAX(num_of_test) = 0 THEN 'Y' ELSE 'N' END all_n
FROM
(SELECT listing_id,
COUNT(DISTINCT listing_test) OVER (PARTITION BY NULL) all_test_cnt,
SUM(CASE WHEN pass_yn = 'Y' THEN 1 ELSE 0 END) OVER (PARTITION BY listing_id)num_of_test
FROM listing_row)
GROUP BY listing_id