我有两个问题:
首先:
select x.year, sum(x.cnt)
from (select count(id)*3 as cnt from takes where year = 2009 group by year) x
group by x.year;我得到的错误是“字段列表中的未知列x.year。我希望查询充当select year, sum(count(id)*3);
第二:
我需要编写一个查询,该查询在不使用外部连接的情况下执行与以下相同的操作:
select instructor.id, name, count(teaches.id) as 'Number of Sections'
from instructor natural left outer join teaches
group by teaches.id, name, instructor.id
order by instructor.id asc;我尝试了以下方法,但不起作用:
(select instructor.id, name, count(teaches.id) as 'Number of Sections'
from instructor, teaches
where instructor.id = teaches.id
group by teaches.id, name, instructor.id)
union
(select i.id, i.name, count(t.id)
from instructor i, teaches t
where i.id not in (select id from teaches)
group by t.id, i.name, i.id);谢谢!
https://stackoverflow.com/questions/47565478
复制相似问题