SQL Server 2008查询:多列值

时间:2015-07-15 16:13:21

标签: sql-server

我有一个查询,我需要选择my.variable <- rnorm(100) bespoke_cut <- function(value){ if (value < 0.1) return('[-Inf, 0.1)') if (value < 0) return('[0.1, 0)') if (value == 0) return('0') return('(0, Inf]') } my.cut <- sapply(my.variable, bespoke_cut) my.cut <- factor(my.cut) project_status_id = 2在过去一年中有一个日期的所有值。不确定这是如何实现的。

这是我的SQL:

project_ship_date

注意SELECT DISTINCT p.id, p.name, CONVERT(VARCHAR(12), s.ship_date, 109) AS ship_date, sp.name as species, p.quoted_sf FROM ProjectTracking.dbo.projects AS p LEFT JOIN ProjectTracking.dbo.shipments AS s ON p.id = s.project_id LEFT JOIN ProjectTracking.dbo.segments AS seg ON p.id = seg.project_id LEFT JOIN ProjectTracking.dbo.species AS sp ON seg.specie_id = sp.id WHERE sp.name LIKE '%maple%' AND (p.project_status_id = 2 OR s.ship_date > "last year?") 的值可能为p.project_status_id

注意#2 :如果1,2,10,11必须指定p.project_status_id != 2

1 个答案:

答案 0 :(得分:2)

SELECT DISTINCT p.id, p.name, CONVERT(VARCHAR(12),s.ship_date,109) AS ship_date, sp.name as species, p.quoted_sf
FROM ProjectTracking.dbo.projects AS p
LEFT JOIN ProjectTracking.dbo.shipments AS s ON p.id = s.project_id
LEFT JOIN ProjectTracking.dbo.segments AS seg ON p.id = seg.project_id
LEFT JOIN ProjectTracking.dbo.species AS sp ON seg.specie_id = sp.id
WHERE sp.name LIKE '%maple%' AND
(p.project_status_id IN (1,2,10,11) OR s.ship_date > DATEADD(year,-1,GETDATE()) )