0

这段代码有效,我只是想学习如何清理它,这样它就不会跨越很多行,并且 where 语句在几行上就很好而且整洁:

SELECT
    case_id, service_type_id 
FROM 
    cases_service_types
WHERE
    dbo.cases_service_types.service_type_id = '3'
    OR dbo.cases_service_types.service_type_id = '4'
    OR dbo.cases_service_types.service_type_id = '5'
    OR dbo.cases_service_types.service_type_id = '6'
    OR dbo.cases_service_types.service_type_id = '8'
    OR dbo.cases_service_types.service_type_id = '9'
4

2 回答 2

2
SELECT
    case_id, 
    service_type_id 
FROM 
    dbo.cases_service_types
WHERE
     service_type_id IN ('3', '4', '5', '6', '8', '9' )

如果您不小心错过了“7”,那么更好的是:

SELECT
    case_id, 
    service_type_id 
FROM 
    dbo.cases_service_types
WHERE
     service_type_id BETWEEN '3' AND '9'
于 2013-09-15T15:52:33.273 回答
2

您正在寻找IN

SELECT case_id, 
       service_type_id 
FROM   cases_service_types 
WHERE  dbo.cases_service_types.service_type_id IN ( 3, 4, 5, 6, 8, 9 ) 
于 2013-09-15T15:52:00.423 回答