Welcome to Sign in | Join | Help
in Search

Select fara UNION

Last post 04-02-2013, 12:18 by ssandu. 4 replies.
Sort Posts: Previous Next
  •  03-05-2013, 4:19 9520

    Select fara UNION

    Salut
    Am un table de forma
    data intrare explicatii
    2000 0 REPORT
    2001 100 ........
    2002 1 .........
    2002 -1 .........
    2003 10 ........
    .
    .
    2013 10 .........
    Trebuie sa selectez cele care au intrari (inclusive cu minus), sunt mai mici de 2013 dar si prima inregistrare care are 0 la intrari.
    Pana la urma am rezolvat-o cu un UNION dar ma interesa daca se poate dintr-un singur SELECT.
    Va multumesc
    Sorin Sandu
  •  03-05-2013, 4:40 9521 in reply to 9520

    Re: Select fara UNION

    Te rog scrie-ne query-ul la care ai ajuns, ca să înţelegem mai bine.
  •  04-01-2013, 8:47 9523 in reply to 9520

    Re: Select fara UNION

    Presupun ca aveti ceva de genul:

    SELECT data, intrare, explicatii
    FROM MyTable
    WHERE data<2013 AND intrare<>0
    UNION
    SELECT TOP 1
    data, intrare, explicatii
    FROM MyTable
    WHERE intrare = 0

    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  04-02-2013, 8:54 9524 in reply to 9523

    Re: Select fara UNION

    Dacă e vorba de query-ul scris de Cristi, atunci se poate rescrie fără UNION astfel:

    SELECT data, intrare, explicatii
    FROM (
    SELECT *, ROW_NUMBER() OVER (PARTITION BY intrare ORDER BY intrare) AS rownum
    FROM MyTable
    ) x
    WHERE data<>0
    OR intrare = 0 AND rownum=1

    Răzvan
  •  04-02-2013, 12:18 9526 in reply to 9524

    Re: Select fara UNION

    Asta e !
    Multumesc
    Sorin Sandu
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems