Существует ли С++-эквивалент оконной функции SQL DENSE_RANK()? [закрыто]C++

Программы на 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»