在具有多个 INNER JOINS 的 SELECT 查询中使用 Count()。找不到正确的输出
这是我的查询:
select distinct
p.*,
d.tech_id,
d.id,
prio.priority
from
data.curated_data s
inner join
data.curated_details p on p.curated_scheme = s.curated_scheme
and p.curated_category = s.curated_category
inner join
data1.data_defn d on d.service_id = p.service_id
inner join
data1.data_priority prio on prio.ingest_data = d.ingest_data
and p.curated_scheme = %s
and s.manually_curated_flag = 'Y'
and s.autosuggest_kind = %s
limit %s
offset %s
这就是我试图做的:
select count(*)
from ( select distinct p.*,
d.tech_id,
d.id,
prio.priority
from data.curated_data s
inner join data.curated_details p on p.curated_scheme = s.curated_scheme and p.curated_category = s.curated_category
inner join data1.data_defn d on d.service_id = p.service_id
inner join data1.data_priority prio on prio.ingest_data = d.ingest_data
and p.curated_scheme = %s
and s.manually_curated_flag = 'Y'
and s.autosuggest_kind = %s
limit %s
offset %s
)
但是,这会导致错误
错误代码:1248。每个派生表必须有自己的别名
为了处理这个问题,我向 count select
查询添加了别名,但随后它返回了错误的输出 1,而表中有大约 500 行输出表。
This is my query:
select distinct
p.*,
d.tech_id,
d.id,
prio.priority
from
data.curated_data s
inner join
data.curated_details p on p.curated_scheme = s.curated_scheme
and p.curated_category = s.curated_category
inner join
data1.data_defn d on d.service_id = p.service_id
inner join
data1.data_priority prio on prio.ingest_data = d.ingest_data
and p.curated_scheme = %s
and s.manually_curated_flag = 'Y'
and s.autosuggest_kind = %s
limit %s
offset %s
This is what I tried to do:
select count(*)
from ( select distinct p.*,
d.tech_id,
d.id,
prio.priority
from data.curated_data s
inner join data.curated_details p on p.curated_scheme = s.curated_scheme and p.curated_category = s.curated_category
inner join data1.data_defn d on d.service_id = p.service_id
inner join data1.data_priority prio on prio.ingest_data = d.ingest_data
and p.curated_scheme = %s
and s.manually_curated_flag = 'Y'
and s.autosuggest_kind = %s
limit %s
offset %s
)
However, this leads to an error of
Error Code: 1248. Every derived table must have its own alias
To handle that I added alias to my count select
query but then it returned a wrong output of 1, while the there is around 500 rows in the output table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在派生表|子查询的末尾使用别名
Try an alias at the end of derived table|subquery