1,3号顾客发票的最大金额
select max(invoice_total)
from invoices
where client_id=3
2,筛选大于3号顾客的所有发票(首先是写出三号顾客最大发票额的查询,其次是写大于3号最大发票额的查询)
做法一:
select *
from invoices
where invoice_total>(
select max(invoice_total)
from invoices
where client_id=3)
做法二:
首先选择蓝色部分,记住括号也要选,得到该结果不止一个
然后全选,执行,发现
Error Code: 1242. Subquery returns more than 1 row
因此需要改为,意思是需要大于()里面的所有值,也就是大于()里面最大值
select *
from invoices
where invoice_total>all(
select invoice_total
from invoices
where client_id=3)