开发者

on sql basic question [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi开发者_高级运维s question so that it can be reopened, visit the help center. Closed 12 years ago.

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.


  1. select sal from empsal union select SUM(sal) from empsal

  2. 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),())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜