易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL查询 高手看一下内容 - MS-SQL Server / 基础类

数据库里有 uid (身份证号) xmname (项目名称) 两个字段 
库内容如下:

uid xmname

1 xxx
1 YYY
1 ZZZ
2 AAA
2 BBB
3 CCC
4 DDD

我想查询 相同 uid 的 xmname 同时有xxx 和yyy 的人有哪些,,怎么查啊,, 记录出来必须唯一!!!

select uid 
from tb t
where xname='xxx' or xname='yyy'
having count(*)>2

SQL code:
select uid
from tb t
where xname='xxx' or xname='yyy'
having count(*)>2
group by uid


select distinct uid
from tb k  
where exists(select * from tb where k.uid=uid and xmname='XXX')
and exists(select * from tb where k.uid=uid and xmname='YYY')

SQL code:


IF object_id('tb')IS NOT NULL DROP TABLE tb
CREATE TABLE tb(uid INT,xmname VARCHAR(5))
INSERT INTO tb
SELECT 1, 'xxx'UNION ALL
SELECT 1 ,'YYY' UNION ALL
SELECT 1 ,'ZZZ'UNION ALL
SELECT 2 ,'AAA'UNION ALL
SELECT 2 ,'BBB'UNION ALL
SELECT 3 ,'CCC'UNION ALL
SELECT 4 ,'DDD'



SELECT * from (
SELECT DISTINCT uid,xmname=stuff((SELECT ','+xmname from tb WHERE uid=a.uid FOR xml path('') ),1,1,'')
from tb a
)c
WHERE charindex('xxx,YYY',xmname)>0




引用<


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

SQL如何优化问题 - MS-SQL Server / 疑难问题

今天做了一个存储过程   环境是SQL2000数据库  
大致如下
建立临时表
定义员工游标
        循环员工(属于1个公司)  
        ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号