英文:
How to hidden employee name duplicate sql
问题
我想要从这里隐藏员工姓名
到这里
查询
SELECT
XU.EMP_NAME,
XU.FUNCTION,
XU.ROLE_ACCESS
FROM
XX_USERS XU LEFT JOIN
XX_USERS_ACCESS XUA ON XU.EMP_ID=XUA.EMP_ID
WHERE
NVL(XU.STATUS,'N')='Y'
order by XU.EMP_NAME
可以吗?
英文:
i want to hide employee name from this
To this
Query
SELECT
XU.EMP_NAME,
XU.FUNCTION,
XU.ROLE_ACCESS
FROM
XX_USERS XU LEFT JOIN
XX_USERS_ACCESS XUA ON XU.EMP_ID=XUA.EMP_ID
WHERE
NVL(XU.STATUS,'N')='Y'
order by XU.EMP_NAME
its posible ?
答案1
得分: 1
根据您标记的问题中的PL/SQL
标签(这表明您可能正在使用Oracle和MySQL
一起使用),那么:我没有您的表,但我有Scott的示例模式。 模拟您的情况的查询如下:
SQL> select d.dname, e.ename, e.job
2 from emp e join dept d on d.deptno = e.deptno
3 order by d.dname, e.ename;
DNAME ENAME JOB
-------------- ---------- ---------
ACCOUNTING CLARK MANAGER
ACCOUNTING KING PRESIDENT
ACCOUNTING MILLER CLERK
RESEARCH ADAMS CLERK
RESEARCH FORD ANALYST
RESEARCH JONES MANAGER
RESEARCH SCOTT ANALYST
RESEARCH SMITH CLERK
SALES ALLEN SALESMAN
SALES BLAKE MANAGER
SALES JAMES CLERK
SALES MARTIN SALESMAN
SALES TURNER SALESMAN
SALES WARD SALESMAN
14 rows selected.
如果您使用SQL*Plus,您可以设置break
:
SQL> break on dname
SQL> /
DNAME ENAME JOB
-------------- ---------- ---------
ACCOUNTING CLARK MANAGER
KING PRESIDENT
MILLER CLERK
RESEARCH ADAMS CLERK
FORD ANALYST
JONES MANAGER
SCOTT ANALYST
SMITH CLERK
SALES ALLEN SALESMAN
BLAKE MANAGER
JAMES CLERK
MARTIN SALESMAN
TURNER SALESMAN
WARD SALESMAN
14 rows selected.
或者,对行进行排序(使用row_number
分析函数),并有条件地显示列值:
SQL> with temp as
2 (select d.dname, e.ename, e.job,
3 row_number() over (partition by d.dname order by d.dname, e.ename) rn,
4 row_number() over (order by d.dname, e.ename) rn_sort
5 from emp e join dept d on d.deptno = e.deptno
6 )
7 select case when rn = 1 then dname else null end dname,
8 ename, job
9 from temp
10 order by rn_sort;
DNAME ENAME JOB
-------------- ---------- ---------
ACCOUNTING CLARK MANAGER
KING PRESIDENT
MILLER CLERK
RESEARCH ADAMS CLERK
FORD ANALYST
JONES MANAGER
SCOTT ANALYST
SMITH CLERK
SALES ALLEN SALESMAN
BLAKE MANAGER
JAMES CLERK
MARTIN SALESMAN
TURNER SALESMAN
WARD SALESMAN
14 rows selected.
另一方面,类似这样的操作通常应在某个报表工具中使用,大多数(如果不是全部)报表工具都有类似的“分组”选项。通常情况下,我们不在纯SQL中执行此类操作。
英文:
As you tagged the question with PL/SQL
tag (which suggests that you might be using Oracle alongside MySQL
), then: I don't have your tables, but I do have Scott's sample schema. Query that simulates what you have is:
SQL> select d.dname, e.ename, e.job
2 from emp e join dept d on d.deptno = e.deptno
3 order by d.dname, e.ename;
DNAME ENAME JOB
-------------- ---------- ---------
ACCOUNTING CLARK MANAGER
ACCOUNTING KING PRESIDENT
ACCOUNTING MILLER CLERK
RESEARCH ADAMS CLERK
RESEARCH FORD ANALYST
RESEARCH JONES MANAGER
RESEARCH SCOTT ANALYST
RESEARCH SMITH CLERK
SALES ALLEN SALESMAN
SALES BLAKE MANAGER
SALES JAMES CLERK
SALES MARTIN SALESMAN
SALES TURNER SALESMAN
SALES WARD SALESMAN
14 rows selected.
If you used SQL*Plus, you could set a break
:
SQL> break on dname
SQL> /
DNAME ENAME JOB
-------------- ---------- ---------
ACCOUNTING CLARK MANAGER
KING PRESIDENT
MILLER CLERK
RESEARCH ADAMS CLERK
FORD ANALYST
JONES MANAGER
SCOTT ANALYST
SMITH CLERK
SALES ALLEN SALESMAN
BLAKE MANAGER
JAMES CLERK
MARTIN SALESMAN
TURNER SALESMAN
WARD SALESMAN
14 rows selected.
Or, sort rows (using row_number
analytic function) and conditionally display column value:
SQL> with temp as
2 (select d.dname, e.ename, e.job,
3 row_number() over (partition by d.dname order by d.dname, e.ename) rn,
4 row_number() over (order by d.dname, e.ename) rn_sort
5 from emp e join dept d on d.deptno = e.deptno
6 )
7 select case when rn = 1 then dname else null end dname,
8 ename, job
9 from temp
10 order by rn_sort;
DNAME ENAME JOB
-------------- ---------- ---------
ACCOUNTING CLARK MANAGER
KING PRESIDENT
MILLER CLERK
RESEARCH ADAMS CLERK
FORD ANALYST
JONES MANAGER
SCOTT ANALYST
SMITH CLERK
SALES ALLEN SALESMAN
BLAKE MANAGER
JAMES CLERK
MARTIN SALESMAN
TURNER SALESMAN
WARD SALESMAN
14 rows selected.
On the other hand, something like this is supposed to be used in some reporting tool, most (if not all) of them have such a "grouping" option. Usually, we don't do that in pure SQL.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论