AngularJS repeat with table and rowspan - angularjs

Say I have the following data structure
* Key 1
* Value 1
* Value 2
* Key 2
* Value 3
* Value 4
* Value 5
How, with AngularJS, can I render it in a table similar to the following:
|-------|---------|
| Key 1 | Value 1 |
| |---------|
| | Value 2 |
|-------|---------|
| Key 2 | Value 3 |
| |---------|
| | Value 4 |
| |---------|
| | Value 5 |
|-------|---------|
The keys are done via rowspan.

Nice and tricky question!
One way to do it would be:
Given an object like this:
$scope.testData={
key1:[1,2],
key2:[3,4,5]
};
You could do this:
<table>
<tr ng-repeat-start="(key, val) in testData">
<td rowspan="{{val.length}}">{{key}}</td>
<td>{{val[0]}}</td>
</tr>
<tr ng-repeat-end ng-repeat="value in val.slice(1)">
<td>{{value}}</td>
</tr>
</table>
Example

Related

SnowFlake - How to return the column that the least function value came from?

I am doing a Snowflake query where I get RANK from each column.
Output below:
| Rank_A | Rank B |
| -------- | -------- |
| 1 | 3 |
| 2 | 4 |
| 5 | 4 |
Then I do the LEAST function to get the Minimum across those columns
https://docs.snowflake.com/en/sql-reference/functions/least.html
Output below:
| Rank_A | Rank B | LEAST |
| -------- | -------- | -------- |
| 1 | 3 | 1 |
| 2 | 4 | 2 |
| 5 | 4 | 4 |
Lastly, (This is where I am not sure of) How can I make another column that returns what column the Least function came from - so what I am trying to return in this new column is like so:
Expected output below:
| Rank_A | Rank B | LEAST | Column Name of Least Value |
| -------- | -------- | -------- | -------------------------- |
| 1 | 3 | 1 | Rank_A |
| 2 | 4 | 2 | Rank_A |
| 5 | 4 | 4 | Rank_B |
I have no idea how I would go about this? any and all help would be greatly appreciated.
I do not know where to begin. I was contemplating doing this all in python before ingesting the data table?
You could use DECODE to get the first LEAST value column name:
SELECT *
,LEAST(Rank_A, Rank_B)
,DECODE(LEAST(Rank_A, Rank_B),
Rank_A, 'Rank_A',
Rank_B, 'Rank_B') AS column_name
FROM tab;
Output:
We can use a CASE expression along with the LEAST() function:
SELECT
RANK_A,
RANK_B,
LEAST(Rank_A, Rank_B) AS LEAST,
CASE WHEN RANK_A = LEAST(Rank_A, Rank_B)
THEN 'RANK_A' ELSE 'RANK_B' END AS LEAST_VALUE
FROM yourTable;
In the event that RANK_A and RANK_B have the same value, the above query would arbitrarily return RANK_A as the column with the least value.

Best way of storing enumerated fields with ability to change order Postgres

What is the best way for storing enumerated fields with ability to change its order?
Lets say my database looks like this:
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 2 | 2nd | 2 |
| 3 | 3rd | 3 |
| 4 | 4th | 4 |
Now, when user change order in such a away
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 4 | 4nd | 2 |
| 2 | 2nd | 3 |
| 3 | 3rd | 4 |
Here I would have to update all rows in this table.
I consider 2 solutions
Solution 1)
When inserting row X between for example order 2 and order 3, I would change row's X order field to 3.5, So I would choose number in the middle between adjacent orders.
Above table would look like this
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 4 | 4nd | 2.5 |
| 2 | 2nd | 2 |
| 3 | 3rd | 3 |
Then, after for example 16 changes I would update table and normalize all order fields, so table after normalization would be like this:
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 4 | 4nd | 2 |
| 2 | 2nd | 3 |
| 3 | 3rd | 4 |
Solution 2)
I also consider adding fields "next" (or "next" and "prev") to each row, but it looks for me like waste of memory.
I really dont want to update whole table every time somebody change order. What is the best way of solving this problem?

Sphinx RT index and search in json by value

In rt index i have fields - fields with rt_attr_json attributes.
In this field i have such structure (collection of same blocks):
{
block_name: "a",
block_type: 1,
elements: {
{
...
}
}
}
How I can get all records from sphinx which has block_type = 1 and not empty elements in this block?
I know how this realize if I know a key of block:
where fields[0].block_type=1 and fields[0].elements is null;
I am not sure if I completely understood the question, but the following works nicely in Sphinx 3.1.1:
mysql> select * from jt;
+------+-------+-----------------------------+
| id | title | j |
+------+-------+-----------------------------+
| 1 | | {"type":1} |
| 2 | | {"type":1,"elements":[]} |
| 3 | | {"type":1,"elements":[123]} |
| 4 | | {"type":2} |
| 5 | | {"type":2,"elements":[123]} |
+------+-------+-----------------------------+
5 rows in set (0.00 sec)
mysql> select * from jt where j.type=1 and j.elements is not null;
+------+-------+-----------------------------+
| id | title | j |
+------+-------+-----------------------------+
| 2 | | {"type":1,"elements":[]} |
| 3 | | {"type":1,"elements":[123]} |
+------+-------+-----------------------------+
2 rows in set (0.00 sec)
Note that any previous versions might behave differently, as NULL handling was fixed to the point of being semi-rewritten in the most recent 3.1.1 release.

How to Write Conditional Statement in SQL Server

I am having a logic issue in relation to querying an SQL database. I need to exclude 3 different categories and any item that is included in those categories; however, if an item under one of those categories meets the criteria for another category I need to keep said item.
This is an example output I will get after querying the database at its current version:
ExampleDB | item_num | pro_type | area | description
1 | 45KX-76Y | FLCM | Finished | coil8x
2 | 68WO-93H | FLCL | Similar | y45Kx
3 | 05RH-27N | FLDR | Finished | KH72n
4 | 84OH-95W | FLEP | Final | tar5x
5 | 81RS-67F | FLEP | Final | tar7x
6 | 48YU-40Q | FLCM | Final | bile6
7 | 19VB-89S | FLDR | Warranty | exp380
8 | 76CS-01U | FLCL | Gator | low5
9 | 28OC-08Z | FLCM | Redo | coil34Y
item_num and description are in a table together, and pro_type and area are in 2 separate tables--a total of 3 tables to pull data from.
I need to construct a query that will not pull back any item_num where area is equal to: Finished, Final, and Redo; but I also need to pull in any item_num that meets the type criteria: FLCM and FLEP. In the end my query should look like this:
ExampleDB | item_num | pro_type | area | description
1 | 45KX-76Y | FLCM | Finished | coil8x
2 | 68WO-93H | FLCL | Similar | y45Kx
3 | 84OH-95W | FLEP | Final | tar5x
4 | 81RS-67F | FLEP | Final | tar7x
5 | 19VB-89S | FLDR | Warranty | exp380
6 | 76CS-01U | FLCL | Gator | low5
7 | 28OC-08Z | FLCM | Redo | coil34Y
Try this:
select * from table
join...
where area not in('finished', 'final', 'redo') or type in('flcm', 'flep')
Are you looking for something like
SELECT *
FROM Table_1
JOIN Table_ProType ON Table_1.whatnot = Table_ProType.whatnot
JOIN Table_Area ON Table_1.whatnot = Table_Area.whatnot
WHERE Table.area NOT IN ('Finished','Final','Redo') OR ProType.pro_type IN ('FLCM','FLEP')
Giving the names of the three tables and the joining criteria will help me improve the answer.

WPF Datagrid Rowspan on one column depend of value

(sorry for my english)
I have a problem with my datagrid.
First, my datagrid is fill from a database, depend of a value selected in a combobox. When the SelectedValue of my combobox change the datagrid ItemsSource is refresh with good value.
For now my datagrid look like that
|---|---|---|
| A | + | 1 |
|---|---|---|
| A | - | 1 |
|---|---|---|
| B | + | 2 |
|---|---|---|
| C | - | 1 |
|---|---|---|
I would like to span row of column with number if letter are equal. Because the value of number is linked to the letter value.
To make the datagris look like
|---|---|---|
| A | + | |
|---|---| 1 |
| A | - | |
|---|---|---|
| B | + | 2 |
|---|---|---|
| C | - | 1 |
|---|---|---|

Resources