Example i having a table name DEPARTMENT
//DEPARTMENT
D#
--------
1
2
3
Now having a project table
//Project
P# D#
-----------
1 1
2 1
3 2
4 1
So how should i use the group by with specific column name when display out all the information using prompt, it should be something like
Enter Department Number : 1
D# total project
---------------------
1 3
So far i done like this
ACCEPT dno PROMPT 'Enter Department Number: '
SELECT DNAME FROM DEPARTMENT WHERE D#=&dno;
SELECT count(*) from PROJECT where D#=&dno;
use this
select DNAME, count(Project) AS "total project" FROM DEPARTMENT d, PROJECT p
WHERE d.dno=p.dno and D.DNO=&dno group by DNAME;
to get total only
select count(Project) AS "total project" FROM DEPARTMENT d, PROJECT p
WHERE d.dno=p.dno and D.DNO=&dno group by DNAME;
Try JOIN between two tables,
ACCEPT dno PROMPT 'Enter Department Number: '
SELECT DNAME, count(*)
FROM DEPARTMENT d, PROJECT p
WHERE d.dno=p.dno and d.dno=&dno
group by d.DNAME;
EDIT
Displaying dno
and DNAME
along with count of projects
ACCEPT dno PROMPT 'Enter Department Number: '
SELECT d.dno,DNAME, count(*) as 'total'
FROM DEPARTMENT d, PROJECT p
WHERE d.dno=p.dno and d.dno=&dno
group by d.dno,DNAME;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.