日期:2014-05-17  浏览次数:20463 次

求租帮忙看看能不能实现一个SQL
比如我数据库中有1,2,3,4 我查询条件是1,2,3,4,5,6要显示5,6求助能否实现这个SQL

------解决方案--------------------
SQL code
--IF object_id('t1') IS NOT NULL
--    DROP TABLE t1
CREATE TABLE t1(ID INT IDENTITY(1,1) PRIMARY KEY,col1 INT)

INSERT INTO t1 (col1) VALUES(1)
INSERT INTO t1 (col1) VALUES(2)
INSERT INTO t1 (col1) VALUES(3)
INSERT INTO t1 (col1) VALUES(4)

SELECT a.number,b.col1 FROM (
            SELECT number FROM master..spt_values WHERE type='p' AND number IN('1','2','3','4','5','6')
        ) AS a
    LEFT JOIN t1 AS b ON a.number=b.col1

------解决方案--------------------
探讨

引用:
SQL code
--IF object_id('t1') IS NOT NULL
-- DROP TABLE t1
CREATE TABLE t1(ID INT IDENTITY(1,1) PRIMARY KEY,col1 INT)

INSERT INTO t1 (col1) VALUES(1)
INSERT INTO t1 (col1) VAL……