Just in advance, I have no access to the SQL query written, so all I can do is try to handle the dataset after the query has executed.
I'm using ASP.NET Webforms to try and merge only one column across a SQL returned datatable e.g
PID | C1 | C2 | C3 | I1
1 | a | a | a | bob
1 | x | x | x | Jim
1 | b | b | b | Fred
2 | g | g | g | Jill
From this Dataset I would like to see:
PID | C1 | C2 | C3 | I1
1 | a | a | a | bob Jim Fred
2 | g | g | g | Jill
Essentially I don't care what is in C1-C3, it will just take the values of the first match. What I need to do though is join all the values of I1 into the one result based on a matching PID.
Any help would be greatly appreciated. LINQ answers acceptable, preferably in vb.net so I don't have to change it later.
Thank you.
You can use the group by with the String.Join. Ia,m adding answer in c# you might want to convert to vb(I not very well with vb syntax :P).
var result = dataListObject.GroupBy(l => l.PId )
.Select(g => new { PID = g.Key.PId, C1= g.Key.C1, C2 = g.Key.C2, C3=g.Key.C3, I1 = string.Join(",", g.Select(i => i.I1)) });
Should select the first PID, C1 ,C2 and C3. Then join the I1 together. Haven't checked this but seems like it should work.
UPDATE
For datatable you can apply the AsEnumerable() to datatable to make it enumerable
var result = datatable.AsEnumerable().GrouBy(l=>l.Field<string>("Pid"))
.Select(g=>new{PID = g.Key.PId, C1= g.Key.C1, C2 = g.Key.C2, C3=g.Key.C3, I1 = string.Join(",", g.Select(i => i.I1)) });
Related
I'm looking to get the count of query param usage from the query string from page views stored in app insights using KQL. My query currently looks like:
pageViews
| project parsed=parseurl(url)
| project keys=bag_keys(parsed["Query Parameters"])
and the results look like
with each row looking like
I'm looking to get the count of each value in the list when it is contained in the url in order to anwser the question "How many times does page appear in the querystring". So the results might look like:
Page | From | ...
1000 | 67 | ...
Thanks in advance
you could try something along the following lines:
datatable(url:string)
[
"https://a.b.c/d?p1=hello&p2=world",
"https://a.b.c/d?p2=world&p3=foo&p4=bar"
]
| project parsed = parseurl(url)
| project keys = bag_keys(parsed["Query Parameters"])
| mv-expand key = ['keys'] to typeof(string)
| summarize count() by key
which returns:
| key | count_ |
|-----|--------|
| p1 | 1 |
| p2 | 2 |
| p3 | 1 |
| p4 | 1 |
I have a DevExpress.XtraGrid. I want the user to edit one of the columns and, after the edit is made, for the grid to update the value of another column. I tried using the event CustomRowCellEdit, but it threw an error whenever I added that event; I wasn't sure how to change the value of another cell anyway. Can someone explain how to do this?
So I've got a grid like this:
----------------
| A | B | C |
----------------
| 1 | 50 | 100 |
----------------
| 2 | 20 | 40 |
----------------
| 3 | 10 | 20 |
----------------
Let's say the user edits row 1, column B to be 25. After they make the change, I want row 1, column C to be twice what B is. So the end result is below where B1 is the value that is user entered and C1 is calculated based on the value in B1.
----------------
| A | B | C |
----------------
| 1 | 25 | 50 |
----------------
| 2 | 20 | 40 |
----------------
| 3 | 10 | 20 |
----------------
I tried this:
private void myView_CustomRowCellEdit_1(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
string newValue = e.CellValue.ToString();
int index = myView.GetDataSourceRowIndex(e.RowHandle);
myView.SetRowCellValue(index, "B", newValue);
}
but I don't think the "B" referred to the column correctly and I got a run time error with a null reference exception.
The GridView.CustomRowCellEdit event is intended to assign repository items to grid cells conditionally. For your case, it is necessary to handle the GridView.CellValueChanged event instead.
Refer to the Modify and Validate Cell Values help topic for more information.
Suppose i have a datframe with values
Mtemp:
-----+
code |
-----+
Ram |
John |
Tracy|
Aman |
i want to compare it with dataframe
M2:
------+
code |
------+
Vivek |
Girish|
Rum |
Rama |
Johny |
Stacy |
Jon |
i want to get result so that for each value in Mtemp i will get maximum 2 possible match in M2 with Levensthein distance 2.
i have used
tp<-as.data.frame(amatch(Mtemp$code,M2$code,method = "lv",maxDist = 2))
tp$orig<-Mtemp$code
colnames(tp)<-c('Res','orig')
and i am getting result as follow
Res |orig
-----+-----
3 |Ram
5 |John
6 |Tracy
4 |Aman
please let me know a way to get 2 values(if possible) for every Mtemp string with Lev distance =2
Lets say I have a table with columns id and content:
id | content
________________________
1 | abc abr abc as abs
2 | abc arc cre arc
3 | agr ann agd agd agd
What I want is output like this:
{"abc":2,"abr":1,"as":1, "abs":1} # for id 1
{"abc":1,"arc":2,"cre":1} # for id 2
{"agr":1,"agd":3,"ann":1} # for id 3
How could the task be done using Hive?
You'll need this library. It's pretty straightforward to build.
Query:
ADD JAR /path/to/jar/brickhouse-0.7.1.jar;
CREATE TEMPORARY FUNCTION COLLECT AS 'brickhouse.udf.collect.CollectUDAF';
SELECT id
, COLLECT(words, c) AS count_map
FROM (
SELECT id
, words
, COUNT(*) AS c
FROM (
SELECT id, words
FROM db.tbl
LATERAL VIEW EXPLODE(SPLIT(content, ' ')) exptbl AS words ) x
GROUP BY id, words ) y
GROUP BY id
Output:
+----+---------------------------------+
|id |count_map |
+----+---------------------------------+
|1 |{"as":1,"abs":1,"abc":2,"abr":1} |
+----+---------------------------------+
|2 |{"cre":1,"arc":2,"abc":1} |
+----+---------------------------------+
|3 |{"ann":1,"agr":1,"agd":3} |
+----+---------------------------------+
I have two tables
Names
id | name
---------
5 | bill
15 | bob
10 | nancy
Entries
id | name_id | added | description
----------------------------------
2 | 5 | 20140908 | i added this
4 | 5 | 20140910 | added later on
9 | 10 | 20140908 | i also added this
1 | 15 | 20140805 | added early on
6 | 5 | 20141015 | late to the party
I'd like to order Names by the first of the numerically-lowest added values in the Entries table, and display the rows from both tables ordered by the added column overall, so the results will be something like:
names.id | names.name | entries.added | entries.description
-----------------------------------------------------------
15 | bob | 20140805 | added early on
5 | bill | 20140908 | i added this
10 | nancy | 20140908 | i also added this
I looked into joins on the first item (e.g. SQL Server: How to Join to first row) but wasn't able to get it to work.
Any tips?
Give this query a try:
SELECT Names.id, Names.name, Entries.added, Entries.description
FROM Names
INNER JOIN Entries
ON Names.id = Entries.name_id
ORDER BY Entries.added
Add DESC if you want it in reverse order i.e.: ORDER BY Entries.added DESC.
This should do it:
SELECT n.id, n.name, e.added, e.description
FROM Names n INNER JOIN
(SELECT name_id, description, Min(added) FROM Entries GROUP BY name_id, description) e
ON n.id = e.name_id
ORDER BY e.added