I have values in table format
IEnumerable<IEnumerable<Data>> tableResult=new IEnumerable<IEnumerable<Data>>();
//below line doesn't work
tableResult = tableResult.Distinct(row => row("ID"));
tableResult contains value in table format, say(Dummy example). Record I am getting is IEnumerable<IEnumerable<Data>> is not table. Dont expect you will get column name
ID Name Designation
1 Sam Engg
3 Mos Doc
3 Peter Driver
4 Bob Builder
Expected result is : How to get unique rows by ID using linq.
ID Name Designation
1 Sam Engg
3 Mos Doc
4 Bob Builder
You can group by id and select the first item in each ID group.
Assuming your ID column is the first element in the inner IEnumerable:
tableResult.GroupBy(x => x.First()).Select(x => x.First());
If you want to have a more specific definition of what row you want to display when you have duplicate ID:s you replace .Select(x => x.First()) with .Select(x => x.OrderBy(y => y.Skip(n).First()).First()) where n is the column number to sort on.
Related
I have a google Spreadsheet.
Column A = Unique number,
Column B = Desc
In column C, I use data validation from column B. I want when I select 1 value the result in column C should be column A. I tried include image to become more clear. Do you have any ideas?
Thank you.
use:
=IFNA(VLOOKUP(D3, {B:B, A:A}, 2, 0))
or:
=IFNA(FILTER(B:B, A:A=D3))
My table is a follow;
names
1.name
1.name
1.name
2.name
2.name
3.name
The result I want to get is as follows;
name count
1.name 3
2.name 2
3.name 1
My request is
select distinct(name) from names where name=! /.*name*/ group by name
or
select count(distinct(name)) from names where name=! /.*name*/ group by name
My response
1.name
2.name
3.name
or
count 3
Thank for help
You will need to select a field in the query and count the field names in the query
Assuming that there is a field called field is available in the measurement,
select count(field1) from names where group by name should work.
I'm not sure why name=! /.*name*/ where clause is added to the query.
I want to put the value of checked name from a checkbox in oracle apex into a table, but unable to do that.
I tried taking help from google but the steps mentioned didn't work too.
Could you please advise how to do that if I have taken a blank form and then added a checkbox to it, also I fetched the checkbox value from LOV.
As I understand, you are using a List of Values as a source of your checkboxes. Let's say you have following values there:
return value display value
----------------------------
123 andAND
456 Dibya
789 Anshul
321 aafirst
555 Anuj
When you select several values, APEX puts their return values into a string and separate them with :. So for the case in your screenshot the value in item P12_NEW will be 123:555. To split this values you can use the following query:
select regexp_substr(:P12_NEW, '[^:]+', 1, level) values
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
The result will be:
values
------
123
555
Next, you need to put these values into table usr_amt (let's say with columns user_id and amount, and the amount is entered into item P12_AMOUNT):
merge into usr_amt t
using (select regexp_substr(:P12_NEW, '[^:]+', 1, level) user_id
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
) n on (n.user_id = t.user_id)
when matched then update
set t.amount = :P12_AMOUNT
when not matched then insert (user_id, amount)
values (n.user_id, :P12_AMOUNT)
This query will search for the each user_id selected in the table, and if the user presents there, updates the corresponding value to the value of item :P12_AMOUNT, if not present - inserts a row with user_id and the value.
I hava one MySQL Table
id name birthdate city
1 Owen 2011/01/01 USA
2 Mark 2012/05/01 UK
3 Marry 2011/01/01 JP
4 John 2011/01/01 JP
First,I uesd jqgrid to read all row data. But Now,I want to know when birthdate=2011/01/01,how many different city in the table.
Can don't used sql,only used jqgrid plugin?
You are looking for distinct function.
SELECT DISTINCT(city) FROM table WHERE birthday = "2011/01/01";
What i want to achieve is simple thing like this using linq to entity. I want to filter the country id only after group by and select clause. However, i can't seem to achieve this simple linq. Applying filtering before group by will results in different key value produce, which is not something that i would expect. The key value that results before groupby is needed.
To put is simple of what i would like to achieve:
Get the key value (r.Key) of certain CountryID
Table:
ID CountryID
1 1
2 1
3 1
4 2
5 1
6 3
_db.TableA.GroupBy(q => q.CountryID).Select(r => r.Key).Where(q => q.CountryID == 2)