select activityname,isnull(countryname,'ALL') as countryname from activity a right join country b on a.countryCode = b.countryCode举点示例数据来看看是什么意思
select activityName,isnull(countryName,'ALL') as countryName from activity right join country on activity.countryCode = countryb.countryCode
楼上的是解答主要是isnull(countryName,'ALL') as countryName其他的都是两张表的连接查询!
/* 表activity: id(主键), countryCode(外键), activityName 表country : countryCode(主键), countryName */ select Ac.activityName,isnull(Ac.countryCode,null),Co.countryName from activity Ac join country Co on Ac.countryCode=Co.countryCode
from activity a
right join country b
on a.countryCode = b.countryCode举点示例数据来看看是什么意思
from activity
right join country
on activity.countryCode = countryb.countryCode
表activity:
id(主键), countryCode(外键), activityName
表country :
countryCode(主键), countryName
*/
select Ac.activityName,isnull(Ac.countryCode,null),Co.countryName
from activity Ac join country Co on Ac.countryCode=Co.countryCode
语法
ISNULL ( check_expression , replacement_value )
备注
如果 check_expression 不为 NULL,则返回它的值;否则,在将 replacement_value 隐式转换为 check_expression 的类型(如果这两个类型不同)后,则返回前者。参数
check_expression 将被检查是否为 NULL 的表达式。check_expression 可以为任何类型。replacement_value 当 check_expression 为 NULL 时要返回的表达式。replacement_value 必须是可以隐式转换为 check_expresssion 类型的类型。返回类型
返回与 check_expression 相同的类型。示例
A. 将 ISNULL 与 AVG 一起使用
以下示例查找所有产品的重量平均值。它用值 50 替换 Product 表的 Weight 列中的所有 NULL 项。 复制代码
USE AdventureWorks;
GO
SELECT AVG(ISNULL(Weight, 50))
FROM Production.Product;
GO
on a.countryCode=b.countryCode