`

ORACLE 问题

 
阅读更多


 张三 英语
 张三 语文
 张三 英语
 李四 英语
 李四 语文
 
结果
 姓名   英语  语文
 张三    2        1
 李四     1       1

这个用ORACLE 分组怎么查出来?


假设字段为姓名,科目

SELECT 姓名, SUM(CASE 科目 WHEN '英语' THEN 1 ELSE 0 END),
                       SUM(CASE 科目 WHEN '语文' THEN 1 ELSE 0 END)
FROM TAB
group by 姓名

 


问题 2 
查找出 相同姓名的所有人 (不区分大小写) 在 Oracle中啊 纠结死了
表 user
id, name,
1    asdf
1    fghf
1    SDF
1    sdf
1    dflgsdfg
1    dflgsdfg


select a.* from your_table a ,(select count(t.id) as cou form your_table t group by lower(t.name)) y where y.cou>1

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics