在表中彼此隔开2列

时间:2018-07-22 11:26:39

标签: sql

我有一个因子表,它有两列:totalpricepaidprice

我想将总价格的计数除以payprice和* 100,然后将返回结果作为百分比。

select  TotalPrice/PaidPrice as h
from Factors 
where TotalPrice>=PaidPrice

3 个答案:

答案 0 :(得分:0)

表格:

**PAID_PRICE**     **TOTAL_PRICE**
35                        50
40                        45

查询:

SELECT (SUM(PAID_PRICE)/SUM(TOTAL_PRICE))*100
FROM TABLE_NAME WITH (NOLOCK)
WHERE TOTAL_PRICE>=TOTAL_PRICE

尝试一下?

答案 1 :(得分:0)

您可以尝试以下操作:

SELECT (COUNT(PAID_PRICE) / CAST(Total_Price AS FLOAT)) * 100 AS Result
from #Table 
WHERE TOTAL_PRICE >= PAID_PRICE
GROUP by TOTAL_PRICE

http://rextester.com/PKXSYV97387

答案 2 :(得分:-1)

create function cost_sheetNO (@a decimal) 
returns table
return (
  select Vcost_sheet_line.[Cost Sheet No_], Vsales_line.[Costsheet No_], Vcost_sheet_line.[Landing Price], 
         (select SUM(Vcost_sheet_line.[Landing Price]) 
          from Vcost_sheet_line 
          where Vsales_line.[Costsheet No_] = Vcost_sheet_line.[Cost Sheet No_]), 
         Vcost_sheet_line.[List Price]*Vcost_sheet_line.[Special Vendor Discount _], 
         (select @a - sales_headerSO.EC from sales_headerSO)       
          from Vcost_sheet_line, Vsales_line       
          where Vsales_line.[Costsheet No_] = Vcost_sheet_line.[Cost Sheet No_] 
)