/****** Script for SelectTopNRows command from SSMS ******/
SELECT
[ProductID]
,[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[Color]
,[SafetyStockLevel]
,[ReorderPoint]
,[StandardCost]
,[ListPrice]
,[Size]
,[SizeUnitMeasureCode]
,[WeightUnitMeasureCode]
,[Weight]
,[DaysToManufacture]
,[ProductLine]
,[Class]
,[Style]
,[ProductSubcategoryID]
,[ProductModelID]
,[SellStartDate]
,[SellEndDate]
,[DiscontinuedDate]
,[rowguid]
,[ModifiedDate]
FROM [AdventureWorks2012].[Production].[Product]
我希望能够选择至少颜色,大小或样式都不为空的所有记录。因此,对于每个记录,三列中的一列应具有值。 我该如何存档?我很困惑。我根本不知道如何获得它,以便至少有一个列具有值。我使用的是SQL Server 2012
答案 0 :(得分:2)
SELECT * FROM PRODUCT
WHERE COLOR IS NOT NULL
OR SIZE IS NOT NULL
OR STYLE IS NOT NULL
答案 1 :(得分:1)
只做
select (columns you want here)
from Table
where (columns that you are matching) is not null
我建议阅读sql的基本教程,以便更好地理解SQL的工作原理。
答案 2 :(得分:1)
我可能会这样做......
select *
from production.product as prod
where coalesce(prod.color, prod.size, prod.style) is not null