我怎样才能在sql中多次计数?

时间:2013-06-02 06:40:52

标签: sql

我尝试使用以下查询

Select cost + scost from
(Select count(order no) as cost 
From platter order where cost= cost*25*discountpercent) ,
(Select count(order no)as scost from schoolorder
Where scost=scost*25);

我正在学习SQL,所以PLZ不介意

2 个答案:

答案 0 :(得分:0)

我认为你正在寻找这个:

SELECT
   (cost + scost) as Total_Cost,
   ((cost + scost) * 25 * discountpercent) as Discounted_Cost,
   count(order_number) as Order_Count
FROM
   schoolorder
WHERE
   scost = scost * 25

答案 1 :(得分:0)

这是一种方法:

Create table #temp (cost as decimal(1,2), scost as decimal(1,2))

INSERT INTO #temp
(Select count(order no) as cost From platter order where cost= cost*25*discountpercent) ,
(Select count(order no)as scost from schoolorder
Where scost=scost*25);

Select cost + scost from #temp

如果我们正确地理解你,你想得到成本和scost的总和吗?

同样在SQL中,你的名字中不能有空格:如果你必须使用空格,拼盘顺序应该是拼盘顺序或[拼盘顺序]。