DECLARE @sometable TABLE ( col1 CHAR(1), col2 CHAR(1), va...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mathematics Meta

Q&A about the site for people studying math at any level and professionals in related fields

DECLARE @sometable TABLE
(
col1 CHAR(1),
col2 CHAR(1),
val INT
)
INSERT INTO @sometable
SELECT 'A','B',3 UNION ALL
SELECT 'C','D',1 UNION ALL
SELECT 'E','F',2 UNION ALL
SELECT 'G','H',4

DECLARE @summa INT

SELECT @summa =  SUM(val) FROM @sometable;

SELECT * 
  FROM @sometable o 
 WHERE (
        SELECT SUM(val) 
          FROM @sometable i 
         WHERE i.val <= o.val
       ) >= 0.6*@summa;

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results