Welcome to Sign in | Join | Help
in Search

Autoincrement Field

Last post 03-11-2009, 2:39 PM by Diana. 2 replies.
Sort Posts: Previous Next
  •  03-11-2009, 11:51 AM 6888

    Autoincrement Field


    Am o intrebare legata de un cimp autoincrement care sa se reseteze in functie de o alta valoare:

    select nr_comanda, produs, pozitie_comanda, sum(cantitate), client from
    comenzi left join clienti
                 left join produse
    group by nr_comanda, produs, pozitie_comanda, client
    order by comanda

    ma inteereseaza ca la fiecare comanda sa pot numara produsele aferente ei. ex:
    nrcomanda      produs       pozitie_comanda       client
        1                   apa                      1                  gigi
        1                 telefon                    2                  gigi
        1                   ciment                  3                  gigi
        2                     apa                    1                   fane
        2                     vodca                 2                   fane
        2                     cola                   3                     fane
        2                     pepsi                 4                       fane
  •  03-11-2009, 11:54 AM 6889 in reply to 6888

    Re: Autoincrement Field

    Vedeti sectiunea Sequentially Numbering Groups of Records.
    Cristian Andrei Lefter, SQL Server MVP
    MCTS, MCITP - Database Administrator SQL Server 2005
  •  03-11-2009, 2:39 PM 6890 in reply to 6888

    Re: Autoincrement Field

    Daca lucrezi pe SQL 2005 poti incerca sa adaptezi acest exemplu (pentru care am folosit AdventureWorks)

    SELECT soh.SalesOrderID, sod.SalesOrderDetailID, sod.ProductID, sod.OrderQty,

    ROW_NUMBER() OVER (PARTITION BY soh.SalesOrderID ORDER BY sod.SalesOrderDetailID) AS Pos

    FROM Sales.SalesOrderHeader soh JOIN Sales.SalesOrderDetail sod

    ON soh.SalesOrderID = sod.SalesOrderID


View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems