Bahar Jalali

Bahar Jalali

  • NA
  • 185
  • 305k

question about SELECT sum(details.Quantity) FROM Details Group By ProductID

Dec 10 2009 7:04 AM
hi

i have 2 table in my database

1. MyProducts
productID (code of products)
Salecounter (count of sales)

2. Details
ProductID
Quantity(count of selected product in shoppingcart)

now i want sum Quantity field in the table details . potation to that column "productid" in table "details" include repeater productid

that's means several row of the table maybe has same productid because every shopping cart maybe include that;

then i want set column salecounter in table MyProducts with result of sum query for every productid

how can i do that ?

that's my code but has some error
 //sale counter 
string at, sa, bb, kk;
OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("shop.mdb"));
at = " update myproducts set salecounter = (SELECT sum(details.Quantity) FROM Details Group By ProductID) in(select productid from details);";// WHERE EXISTS (select productid from myproducts)";
OleDbCommand cmm = new OleDbCommand(at, con);
// OleDbDataReader drm;
con.Open();
// drm = cmm.ExecuteReader();
// drm.Read();
cmm.ExecuteNonQuery();
con.Close();

//


Answers (3)