Question: Consider a very simple application with the project structure

```
-- package.json
-- webpack.config.js
-- src
    |---index.js
    |---runner.js

```

The index.js takes in command line arg to require a file, at runtime. Here is index.js:

```
function requireAtRuntime(filename){
    const runner = require(filename);
    runner.run()
}

var filename = process.argv[2];
requireAtRuntime(filename);

```

runner.js

```
function run(){
    console.log("hello world");
}

exports.run = run

```

package.json contains the script:

```
//
scripts :{  
  "start" : "node src/index.js ./runner.js"
}

```

This start scripts work well. Now the issue if I want to webpack index.js, runner.js is not included as it dependency and the bundle throws the error when i try to run

```
node dist/main.js path/to/runner.js
Error: Cannot find module 'path/to/runner.js'

```

How do I build my webpack so that it can too take filename as command line argument and require it during runtime (or store it before somewhere)?

Answer: 
Supposing that each entrance date has an exit date, you may try the following:

```
Select D.Person,MAX(Entrance) Entrance, MAX(Exit) Exit
From
(
  Select table_name.*,
         MOD(ROW_NUMBER() Over (Partition By Person Order By Entrance, Exit), 
         COUNT(*) Over (Partition By Person)/2) grp
  From table_name
) D
Group By D.Person, D.grp

```

See a [demo](https://dbfiddle.uk/?rdbms=oracle_21&fiddle=6d734ccdeeb1ab88b10ef0ae8ec2515c).
You will have to calculate the next entrance using a `LEAD` function, so you can join your table to itself.

One way to do it is to create two CTEs, one containing all entrances and one containing all exits and join these by `PERSON` and assuring that the exit it picks is later than the entrance, and earlier or equal to the next entrance (or in case there is no next entrance, include it as well, that is what the `COALESCE` is doing in this example:

[db<>fiddle here](https://dbfiddle.uk/?rdbms=oracle_21&fiddle=6853ef2a64de89b4bb30b1baa9d23436)

```
WITH YOUR_TABLE AS (
SELECT 'one' AS PERSON, TO_DATE('09.08.2022', 'DD.MM.YYYY') AS ENTRANCE, NULL AS EXIT FROM DUAL
UNION SELECT 'one', NULL, TO_DATE('10.08.2022', 'DD.MM.YYYY') FROM DUAL
UNION SELECT 'one', TO_DATE('10.08.2022', 'DD.MM.YYYY'), NULL  FROM DUAL
UNION SELECT 'one', NULL, TO_DATE('13.08.2022', 'DD.MM.YYYY') FROM DUAL
UNION SELECT 'two', TO_DATE('08.08.2022', 'DD.MM.YYYY'), NULL  FROM DUAL
UNION SELECT 'two', NULL, TO_DATE('12.08.2022', 'DD.MM.YYYY') FROM DUAL
), 

ENTRANCES AS (
  SELECT 
    PERSON,  
    ENTRANCE, 
    LEAD(ENTRANCE) OVER (PARTITION BY PERSON ORDER BY ENTRANCE) NEXT_ENTRANCE
  FROM YOUR_TABLE
  WHERE ENTRANCE IS NOT NULL),

EXITS AS (
  SELECT PERSON, EXIT FROM YOUR_TABLE
  WHERE EXIT IS NOT NULL)

SELECT ENTRANCES.PERSON, ENTRANCES.ENTRANCE, EXITS.EXIT
FROM ENTRANCES
JOIN EXITS
ON ENTRANCES.PERSON = EXITS.PERSON
AND EXITS.EXIT > ENTRANCES.ENTRANCE 
AND EXITS.EXIT <= COALESCE(ENTRANCES.NEXT_ENTRANCE, TO_DATE('99991231', 'YYYYMMDD'))
ORDER BY 1, 2;

```

disclaimer: This only works if persons can't enter and exit on the same date.