sql查询在同一查询中计数和求和 [英] sql query to count and sum in a same query

查看:549
本文介绍了sql查询在同一查询中计数和求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含10行的表,列是id,name,amount。要计算行数,并在c#表单中使用的单个sql查询中总计所有金额如何..?

i have a table with 10 rows, columns are id, name, amount. To count the no of rows, and to sum all amount in single sql query used in c# form how..?

推荐答案

非常简单。

Very simple.
select count(*),sum(amount) from table_name



如果这不起作用,请尝试以下查询。


If this doesn't work then try below query.

select (select count(*) from table_name) as 'count',(select sum(amount) from table_name) as 'sum of amount'


这篇关于sql查询在同一查询中计数和求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆