0

mulitiテーブルの結合が必要です。1データ/2レコードを表示しますが、実際には1データ/1レコードを表示します。

select acl.Person_ID as 'CODE'
,pnr.FullName as 'FullName'
,case acl.persontype when 'normal' then 'normal' end as 'Type'
From tbl_aculog acl left join tbl_PerNR pnr On acl.Person_ID=pnr.Person_ID

union

select acl.Person_ID as 'CODE'
,ps.FullName as 'FullName'
,case acl.persontype when 'blacklist' then 'blacklist' end as 'Type'
From tbl_aculog acl left join tbl_Person ps On acl.Person_ID=ps.NPerson_ID

結果:

Person_ID | フルネーム| タイプ
00010132 | 臭い| 正常
00010132 | NULL | ヌル
00000579 | プロム| 正常
00000579 | NULL | ヌル
00001081 | ワトソン| 正常
00001081 | NULL | ヌル
5211080 | SOPIT | ブラックリスト
5211080 | NULL | ヌル

**フィールドPerson_ID&FullName&TypeはNULL値です。

結果が欲しい:

Person_ID | フルネーム| タイプ
00010132 | 臭い| 正常
00000579 | プロム| 正常
00001081 | ワトソン| 正常
5211080 | SOPIT | ブラックリスト

どうもありがとうございました:D

4

2 に答える 2

0

結果からsを削除するには、空の「persontype」を無視するようNULLに指定する必要があります。WHERE acl.persontype IS NOT NULL

select acl.Person_ID as 'CODE'
,pnr.FullName as 'FullName'
,case acl.persontype when 'normal' then 'normal' end as 'Type'
From tbl_aculog acl left join tbl_PerNR pnr On acl.Person_ID=pnr.Person_ID
WHERE acl.persontype IS NOT NULL

union

select acl.Person_ID as 'CODE'
,ps.FullName as 'FullName'
,case acl.persontype when 'blacklist' then 'blacklist' end as 'Type'
From tbl_aculog acl left join tbl_Person ps On acl.Person_ID=ps.NPerson_ID
WHERE acl.persontype IS NOT NULL

編集1

を使用すると、INNER JOINが削除されNULLSます。

select acl.Person_ID as 'CODE'
,pnr.FullName as 'FullName'
,case acl.persontype when 'normal' then 'normal' end as 'Type'
From tbl_aculog acl inner join tbl_PerNR pnr On acl.Person_ID=pnr.Person_ID

union

select acl.Person_ID as 'CODE'
,ps.FullName as 'FullName'
,case acl.persontype when 'blacklist' then 'blacklist' end as 'Type'
From tbl_aculog acl inner join tbl_Person ps On acl.Person_ID=ps.NPerson_ID
于 2012-09-10T15:11:21.770 に答える
0

結果が出ない

もっと:

Result:

Person_ID |    FullName |    Type
00010132 |  Stin|         normal
00010132 |  NULL |        NULL
00000579 |  Plom |        normal
00000579 |  NULL |        NULL
00001081 |  Watson |          normal
00001081 |  NULL |        NULL
5211080 |   SOPIT |       blacklist
5211080 |   NULL |        NULL
NULL | NULL |        NULL
NULL | NULL |        NULL

I want Result:

Person_ID |    FullName |    Type
00010132 |  Stin|         normal
00000579 |  Plom |        normal
00001081 |  Watson |          normal
5211080 |   SOPIT |       blacklist
NULL | NULL |        NULL
NULL | NULL |        NULL

データ関係ですみません。

「njk」コードの結果はNULL VALUEになりませんが、値が重複していない場合はNULL VALUEを表示したい.

改めまして、誠にありがとうございました。:)

于 2012-09-10T16:07:34.517 に答える