求sql大神解答:一条select语句包含多个sum汇总后再乘除运算如何做现在我有两个查询语句A和B,A是select sum(a*b) from tb1 where a in('c');B是select sum(a)from tb1 where a in('c')。请问怎么用一个查询直接得A/B的值呢?说白了就是加权平均
åæ¥æ¯ææ ç¨çä¸æ¯è±æè¾å ¥æ³çâ¦â¦â¦
å¦æABä¸å¨ä¸å¼ 表ä¸è¿è½ç¨ä¸å¥è¯åï¼
追çå¯ä»¥ï¼åªæ¯è¦æ ¹æ®ä¸¤ä¸ªè¡¨çå ³èä¾æ®ï¼ç»åæ¥è¯¢
追é®ä¸¾ä¸ªä¾åï¼å¦ææçAæ¯select sumï¼a*bï¼ from tb1 where a inï¼'c'ï¼ï¼Bæ¯from tb2ãtb1ãtb2表示ä¸åæ份ï¼å段é½åºæ¬ä¸æ ·ï¼è¯·å¤§ç¥å个æ¥è¯¢è¯å¥
æ±è§£ç
就是不知道怎么写,求帮忙
求解答
求sql大神解答:一条select语句包含多个sum汇总后再乘除运算如何做
select sum(a*b) \/ sum(a) from tb1 where a in('c')
sql语句 联表查询 并进行除法运算
先用聚合函数求和,然后再减 SELECT t1.购房人, (t1.总房价- tu.已收款金额) AS UnPaid FROM table1 AS t1, (SELECT sum(t2.已收款金额) AS 已收款金额,房间号 FROM dbo.table2 AS t2 GROUP BY 房间号) as tu WHERE t1.房间号= tu.房间号 ...
SQL语句问题,SUM多个表,我需要详细的代码!
select sum(j.jf)+sum(s.jf) as '总和' from jifen j,select s
SQL先合计一列的总数再分组统计
先把你这个查询语句用括号括起来 下面就这样了 select a.item_code,sum(a.bwet), sum(a.bwet)\/11.83 from (select item_code,bwet from kt_al where packdate>='2012-8-1' and packdate<'2012-8-2') a group by a.item
通过sql查询把多条记录按照一定的条件汇总后的值与另一表的字段值比较...
先按时期排序设行号,汇总小于等于行号的金额,再与付款表行号关联计算。select row_number() (over by 日期) 行号,合同号,日期,汇率,金额,(select sum(金额) 合计金额 from (select row_number() over (order by 日期) 行号,日期,合同号,汇率,金额 from 收汇表) t1 where t1.合同号=t2.合同...
先分组再填充数据的sql语句怎么写
sum(求和)max(最大值)min(最小值)示列代码 select count(需要求条数的字段值) from map;注意:count会自动忽略null,并不把null算入计数,在sql的数学表达式中只要参与运算的一个值为null那么整条数据的结果就为null,还有所有的数据库在运算的时候只要有null参与运算结果一定是null比如:select (aprice...
sql语句中如何实现按多组求sum
insert into test values(1,'a','b');insert into test values(2,'c','b');insert into test values(3,'a','d');commit;select*from test;select t1.b,t1.c,t1.sum_a,t2.sum_a from (select b,c,sum(a) as sum_a from test group by b,c) t1,(select b,sum(a) as ...
sql中如何对多个字段汇总后再比较大小?
这样吗?select x.* from (select ,a + b +c as sum_abc from tab ) as x order by x.sum_abc desc;
SQLServer中SQL语句如何对两个group By后的查询结果进行相除?
你错误的问题点在于两个子查询之间没有任何关联,不能直接除。首先我们要建立关联关系。再除 select a.值1,(case when isnull(b.值2,0)=0 then 0 else a.值1\/b.值2) ---记得除数为0处理 from (select 值2,SUM(值1) AS 值1 from 表1 group by 值2) a innor join (看...
sql取出一个字段的多个值并求和
select 点餐编号 as 账单编号,sum(价格) as 金额 from(select a.点餐编号,b.价格 from 点单 a left join 菜谱 bon ',' + a.点餐单号 + ',' like '%,' + b.菜号 + ',%') c group by 点餐编号