Существует ли С++-эквивалент оконной функции SQL DENSE_RANK()? [закрыто] ⇐ C++
-
Гость
Существует ли С++-эквивалент оконной функции SQL DENSE_RANK()? [закрыто]
Let's say you have a table
Customer | Product Dave | Sneakers Martin | Tooth Brush Andrew | Shirt Dave | Tooth Brush In SQL, you can do
SELECT Customer, Product, DENSE_RANK() OVER (ORDER BY Customer) AS customer_id, DENSE_RANK() OVER (ORDER BY Product) AS product_id Customer | Product | customer_id | product_id Dave | Sneakers | 2 | 2 Martin | Tooth Brush | 3 | 3 Andrew | Shirt | 1 | 1 Dave | Tooth Brush | 2 | 3 Which can be usefull if you want to split the data into three tables
Customer (customer_id, customer_name) Product (product_id, product_name) Customer_Product(customer_id, product_id) Is there a function in C++ that comes close to what is achieved with DENSE_RANK() in SQL ?
If a range over a structure, with a field for every column in C++ can be seen as an equivalent of a table in SQL.
With hindsight, after the question has been closed, here is the answer:
#include #include #include #include using namespace std; int main(){ const vector v = {7,9,9,7}; const auto dense_rank = views::zip(v | ranges::to(),views::iota(0)) | ranges::to() ; return 0; } Unfortunately, it requires implicit conversion from tuple to pair, so it does not compile with g++14 at the moment.
Источник: https://stackoverflow.com/questions/780 ... w-function
Let's say you have a table
Customer | Product Dave | Sneakers Martin | Tooth Brush Andrew | Shirt Dave | Tooth Brush In SQL, you can do
SELECT Customer, Product, DENSE_RANK() OVER (ORDER BY Customer) AS customer_id, DENSE_RANK() OVER (ORDER BY Product) AS product_id Customer | Product | customer_id | product_id Dave | Sneakers | 2 | 2 Martin | Tooth Brush | 3 | 3 Andrew | Shirt | 1 | 1 Dave | Tooth Brush | 2 | 3 Which can be usefull if you want to split the data into three tables
Customer (customer_id, customer_name) Product (product_id, product_name) Customer_Product(customer_id, product_id) Is there a function in C++ that comes close to what is achieved with DENSE_RANK() in SQL ?
If a range over a structure, with a field for every column in C++ can be seen as an equivalent of a table in SQL.
With hindsight, after the question has been closed, here is the answer:
#include #include #include #include using namespace std; int main(){ const vector v = {7,9,9,7}; const auto dense_rank = views::zip(v | ranges::to(),views::iota(0)) | ranges::to() ; return 0; } Unfortunately, it requires implicit conversion from tuple to pair, so it does not compile with g++14 at the moment.
Источник: https://stackoverflow.com/questions/780 ... w-function
Мобильная версия