首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

一个基础的查询

2012-05-22 
求助一个基础的查询Table_personTable_liketodoaxbycxdzaybx假设有一个表,表A 是人的姓名 表B 是喜欢做的

求助一个基础的查询
Table_person Table_liketodo
  a x
  b y
  c x
  d z
  a y
  b x



假设有一个表,表A 是人的姓名 表B 是喜欢做的事
如何查询出每个人有多少个喜欢做的事

select distinct person, count(liketodo)
from table
where person = person and liketodo <> liketodo;

我以为这样写,结果说不是一个single function

[解决办法]

SQL code
--如果 是一个表select person, count(liketodo)from tablegroup by person;--两个表(表B可能是每个人的id了?  用id关联取名称)select a.person, count(b.liketodo)from tb1 a,tb2 bwhere a.personid = b.personid;group by a.person 

热点排行