score:1
Proper tu use having count(distinct STATUS=1)
:
create table tableA( ProjectID int, STATUS varchar2(10) );
insert all
into tableA values(1 ,'NEW')
into tableA values(1 ,'CHANGED')
into tableA values(2 ,'NEW')
into tableA values(3 ,'CHANGED')
select * from dual;
/
select * from
(
select ProjectID, max(STATUS) STATUS
from tableA
group by ProjectID
having count(distinct STATUS)=1
)
where STATUS = 'NEW';
score:1
Something like this, perhaps?
SQL> with test (projectid, status) as
2 (select 1, 'new' from dual union -- should be returned
3 select 2, 'new' from dual union
4 select 2, 'closed' from dual union
5 select 3, 'closed' from dual union
6 select 4, 'new' from dual -- should be returned
7 )
8 select projectid
9 from test
10 group by projectid
11 having min(status) = max(status)
12 and min(status) = 'new';
PROJECTID
----------
1
4
SQL>
score:0
I believe I have accomplished what you want, using a subquery in LINQ.
var query = (from a in context.A
where (from b in context.A
where b.ProjectID == a.ProjectID
select new { a.ProjectID, a.STATUS }).Distinct().Count() == 0
&& a.STATUS == "NEW"
select a.ProjectID).ToList();
Essentially, the outer query just makes sure that each a
record has a NEW
status, and the inner query makes sure that there are no two distinct records with the given ProjectID, because if there are, one is CLOSED
. I avoided using a GROUP BY
since you said your database does not support LINQ's way of doing it.
I hope I understood your problem correctly, and I hope this helps!
Source: stackoverflow.com
Related Articles
- GROUP BY, ORDER BY and taking first in LINQ
- C# - LinQ - Read text files, group by first column and order by last column?
- How to get first record in each group using Linq
- Linq Order by a specific number first then show all rest in order
- Linq order by, group by and order by each group?
- Linq Query Group By and Selecting First Items
- LINQ group by then order groups of result
- linq group by, order by
- Entity Framework - Linq query with order by and group by
- Linq to SQL using group By, and order by count
- passing dynamic expression to order by in code first EF repository
- NHIbernate (3.1) - Linq group by then order by count issue
- Linq group by parent property order by child
- Linq - Group by first letter of name
- Linq to SQL Left Join, Order and Group By Count
- Linq Group By not taking inner entity
- LINQ Source Code Available
- How do I order the elements in a group by linq query, and pick the first?
- Converting SQL containing top, count, group and order to LINQ (2 Entities)
- Linq with where clause in many-to-many EF Code First object
- Selecting first element of a group from LINQ search results
- LINQ group by and order by in C#
- Group by a list of words by their first letter in LINQ
- Linq Group by and Order by
- LINQ group by date descending, and order by time ascending
- LINQ and EntityFramework: Getting first result after group by
- How to use Linq group a order list by Date
- creating Linq to sqlite dbml from DbLinq source code
- EF Code First - Linq to Entities Union EqualityComparer
- LINQ Join / Union two lists of objects taking precedence from second over first
- Convert a sql query with a subquery into a linq statement
- Split string when reading a file and ignore one string LINQ
- How to replace xml content in conditionally selected elements using linq (VB 2008)
- Linq Where list Contains item in another list
- PredicateBuilder does not work with Where clause
- Find in the List of words with letters in certain positions
- Left outer join with multiple where condition with LINQ giving null reference error
- Dictionary of Arrays to Single Array
- c# Linq List - handle null
- EF SQL changed when passing predicate as Parameter to Where Clause
- Select most frequent value and count using LINQ and assign to dictionary
- Entity framework where, order and group
- How can i create pagination properly with List<IGrouping<string,Product>>?
- Entity Framework 6 vs Dapper vs stored procedure vs request in SQL Server
- Char[] array help needed
- asp.net linq group by id
- How to do full outer join 2 data tables
- Linq Min in Select new & Multiple GroupBy columns
- LINQ Select() or ForEach loop
- How do I get all items in a list that are inside of another list?