@Select("select sum() from orders where order_state='已支付' and check_in_state='已退房'")怎么sum查询出来的行的总量
时间: 2024-03-27 10:40:02 浏览: 12
`sum()`函数是用来计算某一列的数值总和的,而不是行数的总量。如果你想查询满足条件的行的总量,可以使用`count()`函数,例如:
```
@Select("select count(*) from orders where order_state='已支付' and check_in_state='已退房'")
int getOrderCount();
```
这个方法会返回满足条件的行的总量。
相关问题
select sum(order_amt) from source_pay_info where epay_status='0' and contract_no='' and link_id = 1
这是一个 SQL 查询语句,用于从 `source_pay_info` 表中查询符合条件的订单金额总和。
查询条件如下:
- `epay_status` 等于 '0'
- `contract_no` 为空字符串
- `link_id` 等于 1
查询语句如下:
```
SELECT SUM(order_amt) FROM source_pay_info WHERE epay_status='0' AND contract_no='' AND link_id = 1;
```
该查询将返回满足条件的订单金额总和。
select * form aa where hosp_type=2 and displayorder>=0 and (hosp_state=0 or hosp_state=1);优化下
该查询语句可以进行以下优化:
1. 为 hosp_type、displayorder 和 hosp_state 字段添加索引,以加快查询速度和减少资源消耗。
2. 更改查询语句,使用 UNION ALL 操作符将 hosp_state=0 和 hosp_state=1 的记录分为两个查询,然后将结果组合在一起。这将减少查询的负载,提高查询性能。
优化后的 SQL 查询语句如下:
SELECT *
FROM aa
WHERE hosp_type = 2 AND displayorder >= 0 AND hosp_state = 0
UNION ALL
SELECT *
FROM aa
WHERE hosp_type = 2 AND displayorder >= 0 AND hosp_state = 1
注意:这只是一种优化的思路,实际情况需要根据具体的数据库、数据量和查询需求进行具体的调整。