gpt4 book ai didi

mysql - 使用SQL计算平均客户数

转载 作者:行者123 更新时间:2023-11-29 04:16:48 26 4
gpt4 key购买 nike

enter image description here

数据结构请见上文。我正在尝试编写一个 SQL 查询来获取每个 session 的平均客户数

我的尝试:

select avg(A.NumberCustomer)
from(
select SessionName, count(distinct customers.Idcustomer) as NumberCustomer,
from customers, enrollments, sessions
where customers.Idcustomer=enrollments.Idcustomer and enrollments.Idsession=sessions.Idsession
group by sessions.SessionName
) A

但我似乎在 from customers, enrollments, sessions 行中收到错误对此不确定,感谢任何帮助。

谢谢

最佳答案

你有多余的逗号,你应该删除:

select avg(A.NumberCustomer)
from(
select SessionName,
count(distinct customers.Idcustomer) as NumberCustomer, #<--- here
from customers, enrollments, sessions
where customers.Idcustomer=enrollments.Idcustomer
and enrollments.Idsession=sessions.Idsession
group by sessions.SessionName
) A

顺便说一句,出于可读性原因,我建议您改用 SQL'99 连接语法:

SELECT 
avg(A.NumberCustomer)
FROM (
select
SessionName,
count(distinct customers.Idcustomer) as NumberCustomer
from customers
inner join enrollments
on customers.Idcustomer=enrollments.Idcustomer
inner join sessions
on enrollments.Idsession=sessions.Idsession
group by sessions.SessionName
) A

此外,关于问题的图表很好,下次记得包含您的错误消息。

关于mysql - 使用SQL计算平均客户数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40573757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com