Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 rows which are associated with values greater than

Author  Topic 

alpazar
Starting Member

2 Posts

Posted - 2014-06-05 : 09:46:53
Hi,

I am trying to select all the data which are not associated with values older than a specific value.. For example:
i have:

paola -- 2
paola -- 3
paola -- 10

jessica -- 3
jessica -- 12

james -- 3
james -- 2
james -- 5

I want to query only those names, that are associated with numbers greater than 3. So, for this example, the result would be only Jessica. the others should be discarded.

Please can you help me with this query?

Thank you in advance!
Alpazar


Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-06-05 : 11:58:36
Here is a template:
SELCET <ColumnName1>
FROM <TableName>
WHERE <ColumnName2> > <value>
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-06-06 : 08:37:18
[code]
SELECT *
FROM
(
SELECT *,SUM(CASE WHEN Column2 < 3 THEN 1 ELSE 0 END) OVER (PARTITION BY Column1) AS Occ
FROM Table
)t
WHERE Occ = 0
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

alpazar
Starting Member

2 Posts

Posted - 2014-06-06 : 11:15:45
thnx for your replies..but nothing of them works...:(

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-06-06 : 11:55:06
Missed the part about all the numbers being grater than 3. Not tested, but you need to check against the MIN:
SELECT Name
FROM Table
GROUP BY Name
HAVING MIN(NumberColumn) > 3
Go to Top of Page
   

- Advertisement -