Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Need help...asp.net count sql..

Need help...asp.net count sql..

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nethelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mat daus
    wrote on last edited by
    #1

    im very new to asp.net.
    i develop a website for e-commerce..now i developing a page to display the statistic of the product that bought by costumer..
    here is my database structure..
    Table Product-ProductID,ProductName,Description
    Table Transaction-TransactionID,User,ProductID,Quantity

    -in table Transaction, i store the product that bought by user with user name and quantity.
    -table product, store the information about product

    -this is my data, assume Bag ProductID=1 and Pencil ProductID=2 in table transaction..
    -for table transaction:
    TransactionID | User | ProductID | Quantity
    1 | ali | 1 | 2
    1 | abu | 2 | 3
    1 | qwe | 1 | 5

    i want make a statistic about the product that bought by users..
    im using this Select query= "SELECT Product.ProductName, COUNT(Transaction.ProductID) AS ProductCount FROM Product INNER JOIN Transaction ON Product.ProductID = Transaction.ProductID GROUP BY Product.ProductName"

    when using this query the result is,
    ProductName | ProductCount
    Bag | 2
    Pencil | 1

    i just want my result shown like i stated below..but i dont know how to do it..
    ProductName | ProductCount
    Bag | 7
    Pencil | 3

    please help me....

    P D 2 Replies Last reply
    0
    • M mat daus

      im very new to asp.net.
      i develop a website for e-commerce..now i developing a page to display the statistic of the product that bought by costumer..
      here is my database structure..
      Table Product-ProductID,ProductName,Description
      Table Transaction-TransactionID,User,ProductID,Quantity

      -in table Transaction, i store the product that bought by user with user name and quantity.
      -table product, store the information about product

      -this is my data, assume Bag ProductID=1 and Pencil ProductID=2 in table transaction..
      -for table transaction:
      TransactionID | User | ProductID | Quantity
      1 | ali | 1 | 2
      1 | abu | 2 | 3
      1 | qwe | 1 | 5

      i want make a statistic about the product that bought by users..
      im using this Select query= "SELECT Product.ProductName, COUNT(Transaction.ProductID) AS ProductCount FROM Product INNER JOIN Transaction ON Product.ProductID = Transaction.ProductID GROUP BY Product.ProductName"

      when using this query the result is,
      ProductName | ProductCount
      Bag | 2
      Pencil | 1

      i just want my result shown like i stated below..but i dont know how to do it..
      ProductName | ProductCount
      Bag | 7
      Pencil | 3

      please help me....

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Try this query instead:

      SELECT DISTINCT Product.ProductName, SUM(Transaction.Quantity) AS ProductCount
      FROM Product INNER JOIN Transaction ON Product.ProductID = Transaction.ProductID
      GROUP BY Product.ProductName

      By using COUNT, you were counting the number of lines that corresponded in the result set, not the total.

      Forgive your enemies - it messes with their heads

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      1 Reply Last reply
      0
      • M mat daus

        im very new to asp.net.
        i develop a website for e-commerce..now i developing a page to display the statistic of the product that bought by costumer..
        here is my database structure..
        Table Product-ProductID,ProductName,Description
        Table Transaction-TransactionID,User,ProductID,Quantity

        -in table Transaction, i store the product that bought by user with user name and quantity.
        -table product, store the information about product

        -this is my data, assume Bag ProductID=1 and Pencil ProductID=2 in table transaction..
        -for table transaction:
        TransactionID | User | ProductID | Quantity
        1 | ali | 1 | 2
        1 | abu | 2 | 3
        1 | qwe | 1 | 5

        i want make a statistic about the product that bought by users..
        im using this Select query= "SELECT Product.ProductName, COUNT(Transaction.ProductID) AS ProductCount FROM Product INNER JOIN Transaction ON Product.ProductID = Transaction.ProductID GROUP BY Product.ProductName"

        when using this query the result is,
        ProductName | ProductCount
        Bag | 2
        Pencil | 1

        i just want my result shown like i stated below..but i dont know how to do it..
        ProductName | ProductCount
        Bag | 7
        Pencil | 3

        please help me....

        D Offline
        D Offline
        Dennis E White
        wrote on last edited by
        #3

        just a note but next time don't format your whole question as code. I completely ignored your request because I didn't want to sort through your comments and your code.

        as if the facebook, twitter and message boards weren't enough - blogged

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups