我有以下行:
ID fk_id type comment user ticket
-----------------------------------------------------------
000000658 135 notes afdads abas1 0000000000
000000658 999999 admin NULL 0000000000
000000659 136 notes afadsf admin 0000000001
000000659 999999 admin NULL 0000000001
000000660 999999 admin NULL 0000000000
000000661 999999 admin NULL 0000000006
我想返回 ID 为 000000658 的行,仅返回用户不为空的单个结果,但相同的结果还应返回 ID = 000000659 的用户为空,如下所示:
ID fk_id type comment user ticket
-----------------------------------------------------------
000000658 135 notes fdads abas1 0000000000
000000659 999999 admin NULL 0000000001
000000660 999999 admin NULL 0000000000
000000661 999999 admin NULL 0000000006
我的案例是在仪表板上显示所有投诉并向用户显示他们自己的评论。
我的案例是:我有两个表投诉和投诉详细信息,无论登录到我的页面,我都必须显示所有投诉,但只向用户显示他在票号上输入的评论。为此,我查看了查询的位置:select * from (
SELECT
COMPLAINT.COMP_TICKET_NUM,
999999 COMPLAINT_DETAIL_ID ,
'admin' FLAG,--TO be discuss
' ' NOTES,
null LOGIN_USER,
CURRENT_STATE, CURRENT_ACTOR,CALCULATED_ACTOR,CURRENT_ORG_UNIT--,
--TEMP_FLAG
FROM dbo.COMPLAINT
left outer join COMPLAINT_DETAIL on COMPLAINT_DETAIL.COMP_TICKET_NUM = COMPLAINT.COMP_TICKET_NUM
--where COMPLAINT_DETAIL.LOGIN_USER in ('admin')
union
SELECT
COMPLAINT.COMP_TICKET_NUM,
COMPLAINT_DETAIL.COMPLAINT_DETAIL_ID,
isnull(COMPLAINT_DETAIL.FLAG,'admin') FLAG,--TO be discuss
COMPLAINT_DETAIL.NOTES,
COMPLAINT_DETAIL.LOGIN_USER,
CURRENT_STATE, CURRENT_ACTOR,CALCULATED_ACTOR,CURRENT_ORG_UNIT--,
--TEMP_FLAG
FROM dbo.COMPLAINT
inner join COMPLAINT_DETAIL
on COMPLAINT_DETAIL.COMP_TICKET_NUM =COMPLAINT.COMP_TICKET_NUM