0
Plzz tell how can we use nax(sum()) function in sql
It shows error by this way what is the right way?
5 ответов
+ 1
Can you show us your code?
+ 1
max and sum both will return a single value. So it makes no sense to put sum inside max.
What are you actually trying to do?
+ 1
Yes I can see but what is the result that you want out of that query?
0
create table patient(
patientid int,
patientname varchar(20),
city varchar(20)
);
insert into patient
values(101,'kevin','New York');
insert into patient
values(102,'Mike','Boston');
insert into patient
values(103,'Maria','Chicago');
insert into patient
values(104,'Jenny','New York');
insert into patient
values(105,'Jack','Chicago');
create table consultation(
consultationid int,
patientid int,
fees int
);
insert into consultation
values(1,101,200);
insert into consultation
values(2,102,700);
insert into consultation
values(3,103,600);
insert into consultation
values(4,101,500);
insert into consultation
values(5,105,500);
insert into consultation
values(6,104,500);
select p.patientid,p.patientname,p.city from patient p
inner join consultation c on p.patientid=c.patientid
group by p.patientid,p.patientname,p.city having sum(fees)>
select max(sum(fees)) from patient p1 inner join consultation c1 on
p1.patientid=c1.patientid where patientname like '%e%' group by c1.patientid;
- 1
You can see the code