寻求一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
相关问答:
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......