如何分组工作! [英] How group by works !
本文介绍了如何分组工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT COURSEID, COURSENAME, COURSEGROUP
FROM SOME_VIEW
WHERE STUDENTID=:STU_ID
--GROUP BY COURSEID, COURSENAME
ORDER BY COURSEID
我希望前面的代码像下面的
一样工作
如果我们有2个数据行
COURSEID ------课程名称------ COURSEGROUP
PHY144 ------------物理------------------ A
PHY144 ------------物理------------------ B
我真正需要的是
COURSEID ------课程名称------ COURSEGROUP
PHY144 ----------物理学------------------ A,B
请帮助我
I want the previous code to work like the following
if we have 2 data Rows
COURSEID-------COURSENAME------COURSEGROUP
PHY144----------physics------------------A
PHY144----------physics------------------B
What I really need is
COURSEID-------COURSENAME------COURSEGROUP
PHY144----------physics------------------A, B
please help me
推荐答案
您将必须编写一个子查询.您不能单独使用group by将其用逗号分隔.您可以在此处找到示例 http://stackoverflow.com/questions/7448734/sql-comma-separated-row-with-group-by-子句 [
You will have to write a sub query. You can not have a comma separated aggregate using group by alone. You can find an example here http://stackoverflow.com/questions/7448734/sql-comma-separated-row-with-group-by-clause[^]
hi,
试试这个,
try this,
SELECT COURSEID, COURSENAME, COURSEGROUP
FROM SOME_VIEW
GROUP BY COURSEID, COURSENAME
HAVING STUDENTID=STU_ID
这篇关于如何分组工作!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文