on sql basic question [closed]
Q. display all the salaries and display total sal at the end? Q. how many column are inserted in a single table?
Q1:
SQL> select sum(sal)
2 from emp
3 group by rollup(empno)
4 /
SUM(SAL)
----------
800
1100
1300
1500
1600
3000
3000
5000
950
1250
1250
2450
2850
2975
29025
15 rows selected.
Q2: Please explain this question some more.
Regards, Rob.
select sal from empsal union select SUM(sal) from empsal
I think you want to get the count of columns for a table. You can do that be following query:
select count(*) from information_schema.columns where table_name = ''
Solution 1: Use Roll Up Function for first question
select empno,sum(sal) from emp group by rollup((sal,empno));
Solution 2: Use Grouping Sets
select empno,sum(sal) from emp group by GROUPING SETS ((empno),())
精彩评论