如何更改SQL以显示用户在其帐户中没有的数据库中的数据 [英] How to change SQL to show data from database that a user does not have in their account

查看:64
本文介绍了如何更改SQL以显示用户在其帐户中没有的数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个SQL命令,它从数据库中提取数据,以显示用户有权访问的系统列表,但我不熟悉SQL我不确定如何更改它以显示用户无权访问的系统。



因此,如果我可以访问5个系统中的3个,我需要命令向我展示我无法访问的其他两个系统。



Hi,

I have a SQL command that pulls data from a database to show a list of systems a user has access to but as i am new to SQL i am unsure of how to change it to show what systems the user does not have access to.

So if i have access to 3 of 5 systems i need the command to show me the other 2 systems i do not have access to.

select udesc.description
from u_systems_dev usys, u_user_systems_dev udesc
where usys.system_id = udesc.id
and   usys.user_id = 'username';





我知道这听起来很简单但是在尝试了几天之后这已经难倒把它的一部分做成一个新的命令我不能让它工作。



是这样的吗?..





I know it sounds simple but this has stumped for a couple days after trying to take parts of it to make a new command i cant get it working.

Would it be something like this?..

select udesc.description
from u_usystems_dev usys, u_user_systems_dev udesc
where usys.system_id <> udesc.id
and   usys.user_id <> 'username';







谢谢




Thank you

推荐答案


试试这个:



Hi Try this :

select udesc.description
from u_systems_dev usys
where usys.system_id NOT IN (selct id from u_user_systems_dev )


试试这个:它应该显示来自usys的每一行(带有行)数据 - 可能是某些名称 - 你想要显示)以及用户有权使用的那些项目的描述。



如果你只想要udesc.description然后写ISNULL( udes.description,NO RIGHTS) - ISNULL是sql server函数,在oracle中使用NVL(udesc.description,NO RIGHTS)



这两个函数都会返回如果udesc.description为NULL(即用户在udesc中没有行。







Try this: it should show every row from usys (with the row data - probably some name - you want to show) and the description for those items the user has rights to.

If you want only udesc.description then write ISNULL(udes.description, "NO RIGHTS") - ISNULL is sql server function, in oracle use NVL(udesc.description, "NO RIGHTS")

Both functions will return text NO RIGHTS if udesc.description is NULL (i.e. the user has no rows in udesc.



select usys.some-field, udesc.description
from u_systems_dev usys
LEFT JOIN u_user_systems_dev udesc ON  usys.system_id = udesc.id
WHERE
usys.user_id = 'username';





如果这有帮助请花时间接受解决方案。谢谢。



If this helps please take time to accept the solution. Thank you.


这篇关于如何更改SQL以显示用户在其帐户中没有的数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆