SQLite Administrator concatenate results - sqlite

I have this table
id valor
1 4
1 3
2 2
3 3
3 1
so, I need a consult that the answer be
id valor
1 4,3
2 2
3 3,1
I work with SQLite Administrator..please somebody knows how can I do this?

SELECT id,
group_concat(valor) AS valor
FROM this_table
GROUP BY id

Related

How to create a new table from two different tables in sqlite3?

I want to merge two tables to create a new one. My first database table Data has these kind of information:
cell_id i j
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
6 1 2
7 2 2
8 3 2
9 4 2
10 5 2
Second table whose name is Layer is like that, it contains geometry as record:
geom
blob
blob
blob
blob
blob
I want to create a layer or insert into values in Data to the Layer where j=1 (it means 5 rows in Data table same as Layer table row number). Like that:
cell_id i j geom
1 1 1 blob
2 2 1 blob
3 3 1 blob
4 4 1 blob
5 5 1 blob
How can I handle it in sqlite3?
You may want to CREATE VIEW maybe? That's might be a solution.
CREATE VIEW LayerData AS
SELECT DISTINCT *
FROM Layer L
JOIN Data D
WHERE L.j = 1
Or, as stated by Ignacio Vazquea-Abrams, you can use CREATE TABLE ... AS.

Pulling Specific Row Values based on Another Column

Simple question here -
if I have a dataframe such as:
> dat
typeID ID modelOption
1 2 1 good
2 2 2 avg
3 2 3 bad
4 2 4 marginCost
5 1 5 year1Premium
6 1 6 good
7 1 7 avg
8 1 8 bad
and I wanted to pull only the modelOption values based on the typeID. I know I can subset out all rows corresponding with the typeID, but I just want to pull the modelOption values in this case.

SQLite delete old data

I would like to delete old data from database table. I would just like to keep last 2 records per id. For example I have a table with following records.
ID TIME DATA
1 2 3
1 3 4
1 4 5
2 2 3
2 3 4
2 4 5
2 5 6
Result which I would like to make is (it must be sorted by TIME):
ID TIME DATA
1 3 4
1 4 5
2 4 5
2 5 6
Thank you for your help.
A solution could be:
select * from tab where (
select count(*) from tab as t
where t.ID = tab.ID and t.TIME >= tab.TIME
) <= 2;
for more details visit:
http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

Auto Increment Reseed when another ID has been changed on Insert Query

I Have a two ID that can can be a primary key
SID DEFECT_ID
1 1
1 2
1 3
1 4
1 5
DEFECT_ID is auto increment SID is static and can be another value like 1 or 2 or 3
I need to reseed when sid is another value like this
SID DEFECT_ID
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
3 1
3 2
1 6
1 7
can it be setting in sql server ?
You can use OVER Clause(T-SQL) to get the order number of each ID in your table
SELECT ID
,row_number() OVER (
PARTITION BY ID ORDER BY id ASC
) value
FROM table_name
There's probably a way to do what you're asking, but I have a feeling you might be making it more complicated than it needs to be.
Typically you don't try to "re-seed" like that for identity fields. Instead you end up with output like this:
SID DEFECT_ID
1 1
1 2
1 3
1 4
1 5
2 6
2 7
2 8
3 9
3 10
1 11
1 12
This is how relational databases generally do it and trying to "go against the grain" simply to have the numbers restart for each unique SID is going to be difficult and error-prone.

Find mutually Edges with Spark and GraphX

I'm really new to spark and graphx. My question is that if i have a graph with some nodes that have mutual(reciprocally) edges between them, i want to select the edges with a good performace. An example:
Source Dst.
1 2
1 3
1 4
1 5
2 1
2 5
2 6
2 7
3 1
I want to get the result:
1 2
2 1
1 3
3 1
The order may be arbitrary. Have anyone an idea how i can get this?
Try:
edges.intersection(edges.map(e => Edge(e.dstId, e.srcId))
Note that this compares the Edge.attr values as well. If you want to ignore attr values, then do this:
edges.map(e=> (e.srcId,e.dstId)).intersection(edges.map(e => (e.dstId, e.srcId)))

Resources