Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lambo99
Starting Member
4 Posts |
Posted - 2008-03-02 : 17:17:50
|
| Hi,I am running the query below but I am getting the following results:-Store Prod_no Quant_Sold Total Orders Total_Sale115 M1015 4 4 4000115 M1015 2 1 2000 For some reason on some of the products there is more than one entry for that day per store. As you can see above there is two entries for the product M1015. I need the results to look like the below:Store Prod_no Quant_Sold Total Orders Total_Sale115 M1015 6 5 6000 SELECTstore.branch_no AS store_no, crea_date,jobstock.prod_no,((jobstock.quantity)*COUNT(jobstock.job_id)) AS quantity_sold,COUNT(jobstock.job_id) AS total_orders, SUM(jobstock.total*100) AS store_total, cast (SUM(jobstock.total/1.25)*100 AS INTEGER) AS store_total_before_tax,((((stock.curr_cost*jobstock.quantity)*100)*COUNT(jobstock.job_id))) AS costFROM store, pickup, jobstock, stockWHERE (store.store_id=pickup.store_id)AND (pickup.job_id=jobstock.job_id)AND (stock.prod_no=jobstock.prod_no)AND (stock.store_id=pickup.store_id)AND branch_no>0and crea_date between '2008-02-25' and '2008-02-28'GROUP BY store.branch_no, jobstock.prod_no, jobstock.quantity, stock.curr_cost, crea_dateORDER BY crea_dateAny Ideas would be much appreciated.thanks you. |
|
|
dineshasanka
Yak Posting Veteran
72 Posts |
Posted - 2008-03-02 : 18:01:09
|
| Do not group by jobstock.quantity, stock.curr_cost. Remove thos columns form the Grop by clause---------------------http://dineshasanka.spaces.live.com/ |
 |
|
|
|
|
|
|
|