Answer the question
In order to leave comments, you need to log in
What is the best way to implement the mechanism of "weight" of values in a database table?
Greetings, I titled the subject a little chaotically, I will explain - there are, say, records in the database:
PK name
1 test1
2 test2
5 test3
, etc.
In normal mode, I can display records from the table, sorting them by the main key, or name, but how best to implement such scheme, if I want to, say, first display the value with pk = 5, after already with 1 and 2? It only comes to mind to create a separate table with a 1 to 1 ratio, where the weight of each record will be stored, and every time I want to swap the records, overwrite these same weight keys ... Am I thinking in the right direction, or are there more universal ones for a similar purpose? solutions?
Answer the question
In order to leave comments, you need to log in
To output pk=5 and then 1, 2, try to make a query like:
You didn't specify which database is used, the syntax of the query may differ slightly on different systems, but as a rule, the database allows such calculations in the sort expression.
Write a real example of where and why you need it, without let's say.
Here is a generic and extensible variant:
var auto = [
{
marka: "BMW",
model: "4k",
cuzov: "A",
},
{
marka: "Merc",
model: "4k",
cuzov: "B",
},
{
marka: "Audi",
model: "3k",
cuzov: "C",
},
{
marka: "Toyota",
model: "1k",
cuzov: "D",
},
{
marka: "Lexus",
model: "2k",
cuzov: "E",
},
{
marka: "Rang",
model: "3k",
cuzov: "F",
},
{
marka: "BMW",
model: "4k",
cuzov: "G",
},
{
marka: "BMW",
model: "2k",
cuzov: "Y",
},
{
marka: "Audi",
model: "3k",
cuzov: "U",
}
];
var marka = ["Audi", "Rang", "Merc"];
var model = ["4k", "2k", "3k"];
var cuzov = [];
var params = { marka, model, cuzov };
var activeKeys = Object.keys(params).filter(key => params[key].length);
var rez1 = auto.filter(x => activeKeys.every(key => params[key].includes(x[key])) );
console.log(rez1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question