我有两张桌子ward1和ward2ie;
create table ward1
(
ward_id int
)
create table ward2
(
ward_id int,
ward_name varchar(10)
)和值是 -
insert into ward1 values(101);
insert into ward1 values(101);
insert into ward1 values(102);
insert into ward1 values(102);
insert into ward1 values(102);
insert into ward2 values(101,'child');
insert into ward2 values(102,'General');所以我需要产生ward_id的总数。对我来说,我使用这个代码很简单。
SELECT ward_id, count(ward_id) as "No of occurrence" from ward1 group by ward_id;输出是 -
ward_id No of occurrence
101 2
102 3这是来自ward1表的记录,但是当我想从表ward2的ward_name时。我收到错误。
这是我的代码 -
select ward1.ward_id as "ward_id",ward2.ward_name,
count(ward1.ward_id)as "No of occurrence" from ward1,
ward2 group by ward1.ward_id,ward2.ward_name
having ward1.ward_id=ward2.ward_id;它说不是一组表达...
我想要像这样展示 -
ward_id ward_name No of occurrence
101 child 2
102 General 3请帮忙....