寻求一sql查询 - MS-SQL Server / 基础类
有几千行数据.
查询时候
select * from ssq where 编号 in('1','2','2','4')
如何使编号为2的出现两次
如果
select * from ssq where 编号 in('1','2','2','4','4','4')
使2出现2次,4 出现3次
编号 in 后面可以跟几百个编号的情况,谁有好的解决办法,谢谢了!!
你的数据时什么样的?
select * from ssq where 编号 =1
union all
select * from ssq where 编号 =2
union all
select * from ssq where 编号 =3
union al
select * from ssq where 编号 =4
数据表结构复杂和数据量特别大的时候建议用查询计划仔细份分析 比选一下各种方案
in里出现的重复是不起作用的
SQL code:
----------------------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-05-15 08:58:38
-- Version: Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 2)
-- Blog : http://blog.csdn.net/htl258
----------------------------------------------------------------------------------
--> 生成测试数据表: [TB]
IF OBJECT_ID('[TB]') IS NOT NULL
DROP TABLE [TB]
GO
CREATE TABLE [TB] ([Id] [int],[PId] [int])
INSERT INTO [TB]
SELECT '1','0' UNION ALL
SE
相关问答:
sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
原SQL语句SQL code:
SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......