季獎金10~12月 , 把total為0的去掉(表示是贈的),PartnerNO就是門市。
條件的productNo就是點數表上的產品編號。
SQL有三個條件,期間、產品編號跟total=0要去掉。
我想到以下指令
select partnerno , ProductNo ,TOtal from [EOS].[dbo].[SaleBody] where shipno PartnerNo = 'S0009' and Total <> 0 ;
由於問題有點模糊, 我把我的想法加進來, Tony老大應該是想把10~12月間, 全公司各門市在各個產品的銷售總金額做個查詢, 如果是這樣子的想法...
<pre class="c" name="code">SELECT PartnerNO, ProductNO, SUM(Total)
FROM [EOS].[dbo].[SaleBody]
WHERE Total <> 0
AND LEFT(ShipNo, 5) BETWEEN '10010' AND '10012'
GROUP BY PartnerNO, ProductNO
ORDER BY PartnerNO, ProductNO
如果只是要查單一門市的各產品:
<pre class="c" name="code">SELECT ProductNO, SUM(Total)
FROM [EOS].[dbo].[SaleBody]
WHERE Total <> 0
AND PartnerNO = 'S0002'
AND LEFT(ShipNo, 5) BETWEEN '10010' AND '10012'
GROUP BY ProductNO
ORDER BY ProductNO
如果要查產品在各門市的銷售:
<pre class="c" name="code">SELECT PartnerNO, SUM(Total)
FROM [EOS].[dbo].[SaleBody]
WHERE Total <> 0
AND ProductNO = '07000023'
AND LEFT(ShipNo, 5) BETWEEN '10010' AND '10012'
GROUP BY PartnetNO
ORDER BY PartnerNO
如果要查門市銷售排行:
<pre class="c" name="code">SELECT PartnerNO, SUM(Total)
FROM [EOS].[dbo].[SaleBody]
WHERE Total <> 0
AND LEFT(ShipNo, 5) BETWEEN '10010' AND '10012'
GROUP BY PartnetNO
ORDER BY SUM(Total) DESC
如果要查產品銷售排行:
<pre class="c" name="code">SELECT ProductNO, SUM(Total)
FROM [EOS].[dbo].[SaleBody]
WHERE Total <> 0
AND LEFT(ShipNo, 5) BETWEEN '10010' AND '10012'
GROUP BY ProductNO
ORDER BY SUM(Total) DESC
以上提供Tony老大參考.