I'm doing some comparison, I have datatable with one text column, and I compare each row of datatable with all others.
My point is to avoid double comparison.
I thought writing IDs of compared rows to other datatable, so every time I can check if that two rows are already compared.
Table of already compared rows:
------
1245 4589
5589 6952
2233 2339
So if I want to compare rows with ids 6952 and 5589, I want to see if there is row with columns 6952/5589 or 5589/6952 in table of already compared rows.
What is the simpliest way?
I think you can add another string column which stores compared column IDs in delimited.
i.e. ,1234,5434,32453,
So you just have a string comparison. Compare ,ID, with that column's value
Related
I have 3 different table and each table has Rows and Columns. [r,c]
One of my table has 30 rows and 18 columns,
The second one has 18 rows and 16 columns,
And the last one has 12 Rows and 17 columns.
Number of rows and columns are constant.
I will enter values to this tables. And then I want to save all of this tables to Sqlite. My reference value for insert/select is SheetMetarial.
Instert Into {Table1} (col1, col2...) Values (#col1, #col2, ...)
or
SELECT {SheetMetarial} FROM {Table1};
This way is totally not usefull. So I now my rows(Value1, Value2, ... Val30) and also my columns (Column1, column2, ...) for three tables. What is the best way to make this happen?
Thank you all.
I do not really know what your question is, but if I understood it from the title, you want to insert a multidimensional matrix inside the exact database?
If yes, then you could make a loop over every row in your array (I usually use a matrix inside a multidimensional array) and just apply the columns in its place. Is it that what you mean?
This Post maybe helps you, because there you see a sqlite syntax example for inserting multiple rows, if you want.
How do I compare 2 large DATA tables in C#? The DataTable.Select method takes forever.
I need to compare each record’s field value with the other table. The source and target field data type might be different, e.g. Table1’s field1 data type is INT and Table2’s field1 datatype is VARCHAR.
You need to profile application to find what exactly is slow: iterating through columns and comparing values or finding matching records (rows) that needs to be compared.
As for record, solution could be to convert a table to dictionary. That works if your tables have unique column, then you can convert them to dictionary, where key is unique column value for record and value is whole row. Then iterate first DataTable, get unique column value and get row from 2nd Datatable, but from Dictionary.
If issue is in comparison between 2 rows, then it is better to show the code to see, maybe there are extra comparisons or casts. It's hard to tell without code.
I have a source excel file where my "key" is held in column B. I want to add rows that contain different distinct key values to different tables in a database, using a list of datatables to allow for the number of distinct keys to be variable.
Is it better practise to select the distinct records straight from the sheet itself, or to pull the entire sheet into a "master" datatable and query the datatable for my separate values?
It would be better if you first use distinct and then filter records, it will improve speed and performance.
I have a table like this:
Table name is List.
I have to get sum of each column. I cannot give this query:
SELECT SUM(jayesh,murali,jins) from List;
because the columns are added dynamically. Column names are given as user input. Is there any other code to do this..?
If you want the sum in each column:
SELECT SUM(jayesh), SUM(murali), SUM(jns) from List;
Not saying that any of this is or is not a good idea because no context was provided, but...
Sum of all columns combined for all records (one sum for entire table):
SELECT SUM(jayesh+murali+jns)
FROM List
Sum of all columns for each record (one sum for each row):
(This option requires having an id column to group by so that you can determine how to group the rows)
SELECT
ID,
SUM(jayesh+murali+jns)
FROM List
GROUP BY ID
Sum of each column separately for all records (one sum for each column):
SELECT
SUM(jayesh),
SUM(murali),
SUM(jns)
FROM List
I would also recommend reconsidering your design in adding dynamic columns based on user input. This is generally not a good idea, certainly not for this case. Read more here: http://www.sommarskog.se/dynamic_sql.html
I have a DataTable containing 10 rows and 2 columns which is created from a mdx query, I want to convert this DataTable into html table but before that I want remove duplicated from ONLY FIRST column. How can I do that?
Use LINQ and query it yourself:
myTable.Tables[0].Rows.GroupBy(x => x["Column1Name"]);
Your rows should now be grouped by a distinct Column1Name value, and you can then access it from there.