我在Sybase中有两个表 表1
ID NAME PRICE
123 KING 12.23
234 KONG 23.43
Table2
ID IND CD
123 1 A
When we do "Desc Table2"
Column Name Data Type Null Default Value
ID Int N
IND BIT N 0
CD CHAR Y
因此,当我连接两个表时,table2有一个永远不能为null的列,默认值为0.
select t1.*, t2.IND, t2.CD
from Table1 t1, Table2 t2
where t1.ID *= t2.ID
输出:
ID NAME PRICE IND CD
123 KING 12.23 1 A
234 KONG 23.43 0
期望的输出 我想为table2中找不到的字段显示空值。 当我尝试更新以使其为null时,它给我的消息NULL不允许。 看起来Table2.IND字段最初设置为不允许为空。
输出:
ID NAME PRICE IND CD
123 KING 12.23 1 A
234 KONG 23.43
如何在我的查询中更改此内容,如果table2中不存在数据,我可以看到NULL。
答案 0 :(得分:1)
您应该使用AcceptableIdentifiers : {}
AddProxyAuthorizationRules : exists([Type ==
"http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid", Value
== "S-1-5-32-544", Issuer =~ "^AD AUTHORITY$"]) => issue(Type =
"http://schemas.microsoft.com/authorization/claims/permit", Value =
"true");
c:[Type ==
"http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid",
Issuer =~ "^AD AUTHORITY$" ]
=> issue(store="_ProxyCredentialStore",types=("http
://schemas.microsoft.com/authorization/claims/permit"),query="isProxyTrust
ManagerSid({0})", param=c.Value );
c:[Type ==
"http://schemas.microsoft.com/ws/2008/06/identity/claims/proxytrustid",
Issuer =~ "^SELF AUTHORITY$" ]
=> issue(store="_ProxyCredentialStore",types=("http
://schemas.microsoft.com/authorization/claims/permit"),query="isProxyTrust
Provisioned({0})", param=c.Value );
ArtifactDbConnection : Data Source=np:\\.\pipe\microsoft##wid\tsql\query;Initial
Catalog=AdfsArtifactStore;Integrated Security=True
AuthenticationContextOrder : {urn:oasis:names:tc:SAML:2.0:ac:classes:Password,
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport,
urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient,
urn:oasis:names:tc:SAML:2.0:ac:classes:X509...}
AutoCertificateRollover : True
CertificateCriticalThreshold : 2
CertificateDuration : 365
CertificateGenerationThreshold : 20
CertificatePromotionThreshold : 5
CertificateRolloverInterval : 720
CertificateSharingContainer : CN=6b987b00-35ce-44d9-97c8-561b6f1ac3dd,CN=ADFS,CN=Microsoft,CN=Program
Data,DC=sciemetricdev,DC=com
CertificateThresholdMultiplier : 1440
ClientCertRevocationCheck : None
ContactPerson :
DisplayName : ADFS
IntranetUseLocalClaimsProvider : False
ExtendedProtectionTokenCheck : Allow
FederationPassiveAddress : /adfs/ls/
HostName : *************.com
HttpPort : 80
HttpsPort : 443
TlsClientPort : 49443
Identifier : http://*******.com/adfs/services/trust
InstalledLanguage : en-US
LogLevel : {Errors, Information, Verbose, Warnings}
MonitoringInterval : 1440
NetTcpPort : 1501
NtlmOnlySupportedClientAtProxy : False
OrganizationInfo :
PreventTokenReplays : False
ProxyTrustTokenLifetime : 21600
ReplayCacheExpirationInterval : 60
SignedSamlRequestsRequired : False
SamlMessageDeliveryWindow : 5
SignSamlAuthnRequests : False
SsoLifetime : 480
PersistentSsoLifetimeMins : 10080
KmsiLifetimeMins : 1440
PersistentSsoEnabled : True
PersistentSsoCutoffTime : 1/1/0001 12:00:00 AM
KmsiEnabled : False
LoopDetectionEnabled : True
LoopDetectionTimeIntervalInSeconds : 20
LoopDetectionMaximumTokensIssuedInInterval : 5
PasswordValidationDelayInMinutes : 60
SendClientRequestIdAsQueryStringParameter : False
WIASupportedUserAgents : {MSAuthHost/1.0/In-Domain, MSIE 6.0, MSIE 7.0, MSIE 8.0...}
ExtranetLockoutThreshold : 2147483647
ExtranetLockoutEnabled : False
ExtranetObservationWindow : 00:30:00
:
LEFT JOIN
的 SqlFiddleDemo
强>
输出:
SELECT t1.ID, t1.NAME, t1.PRICE, t2.IND, t2.CD
FROM Table1 t1
LEFT JOIN Table2 t2
ON t1.ID = t2.ID;
答案 1 :(得分:0)
您在查询结果中看到的是LEFT JOIN
(或20岁语法*=
)的工作原理。
如果t1
中有一行ID
而t2
并列ID
,那么
t1 LEFT JOIN t2 ON t1.ID=t2.ID
会从t1
列的NULL
和t2
值返回此行,因为t2
中没有相应的值。
Sybase是否有CASE
声明?
最有可能的是。您可以使用它将这些NULL
值替换为0
或任何您需要的值。
select
t1.*
,CASE WHEN t2.IND IS NULL THEN 0 ELSE t2.IND END AS IND
,t2.CD
from Table1 t1, Table2 t2
where t1.ID *= t2.ID