Need to remove rows with duplicate values in single column and older datestamp

Pages: 12
So is that finally what you want?

If you don't like the blank lines then just take out the code that created them.
if ( previous != "" && e.order_number != previous ) cout << '\n';

I think this thread is finished ...
Just one quick note here.
Below 2 rows can see that only order_number is different, but rest of all are the same.
Is it logical to keep latest order_number and delete old order_number, as both datestamp and activity are same in this case.?

990112678909872002235216 handle payment 2014-03-26 10:32:46.000
990112678909871002435208 handle payment 2014-03-26 10:32:46.000
Last edited on
Is it logical to keep latest order_number and delete old order_number


It's your question, denver2020: you can do what you like with it.

If I was your customer and you deleted my order I would be livid, not logical.
Ok.

I have changed the order with respect to hh:mm:ss, by changing the below lines and got this output:
Is there anyway to change both date (yyyy:mm:dd) and time (hh:mm:ss) by arranging it sequentially ?

1
2
3
if ( a.activity != b.activity ) return a.activity < b.activity;
   return Event( a.date ) < Event( b.date );


AFTER RUN:

order_number activity timestamp

990112678909872002235216 check stock 2014-03-26 10:32:46.000
990112678909872002235216 handle payment 2014-03-26 10:32:46.000

990112678909871002435208 handle payment 2014-03-26 10:32:46.000

990112678909873001235436 register order 2014-01-26 11:42:56.000

990112678909872001235426 register order 2014-02-26 10:32:46.000

990112678909876300123546 register order 2014-03-22 10:31:56.000

990112678909875001235486 register order 2014-03-26 10:25:56.000

990112678909876001235486 register order 2014-03-26 12:26:16.000

990112678909872002235216 ship order 2014-01-26 11:22:46.000
Last edited on
Based on the below info, Is there any way to find out number of times or the average value that the same order_number or activity appears? For example, below row 1 to row 6 has the same activity (which is register order) and row 1 to row 2 has the same order_number.

order_number;activity;timestamp
990112678909876001235486;register order;2014-03-26 10:32:56.000
990112678909876001235486;register order;2014-03-26 12:26:16.000
990112678909875001235486;register order;2014-03-26 10:25:56.000
990112678909876300123546;register order;2014-03-22 10:31:56.000
990112678909873001235436;register order;2014-01-26 11:42:56.000
990112678909872001235426;register order;2014-02-26 10:32:46.000
990112678909872002235216;check stock;2014-03-26 10:32:46.000
990112678909872002235216;ship order;2014-01-26 11:22:16.000
990112678909872002235216;handle payment;2014-03-26 10:32:46.000
990112678909871002435208;handle payment;2014-03-26 10:32:46.000
990112678909872002235216;ship order;2014-01-26 10:00:16.000
990112678909872002235216;ship order;2014-01-26 10:15:26.000
990112678909872002235216;ship order;2014-01-26 11:22:46.000
Create a counter for each each value of order_number that you find, and increment the appropriate counter each time you find that order number.

You'll find std::map useful here.

https://en.cppreference.com/w/cpp/container/map

If you use the order number as the key for each element, and the counter as the value, then you can easily create a new counter when you find a new order number, and easily incrememt the counter for an existing order number. So, if your order number is a string, use std::map<std::string, unsigned int> .
Topic archived. No new replies allowed.
Pages: 12