我有3张表:
a: uid,xm,xb,age,sj,qq
b: uid,money,zt
c: uid,tdate,msxx如果个人填了 xm,就查出这个xm的所有个人资料在a中,如果选了b中money也能找出a中符合money值的数据,如果选了b中zt,c中msxx还是可以找到a中符合要求的个人信息。我这样写的: select aa.uid,aa.xm,aa.xb,aa.age,aa.sj,aa.qq,bb,uid,bb.money,bb.zt,cc.uid,cc.tdate,cc.msxx from a as aa,b as bb,c as cc where aa.uid=bb.uid or aa.uid=cc.uid or aa.uid=cc.uid;--------当然这里还需要加上另一个查询条件,我不知道该怎么写这个查询了,无论怎么写查出的都是空这样写的结果只出来4条,实际上应该是22条。
a: uid,xm,xb,age,sj,qq
b: uid,money,zt
c: uid,tdate,msxx如果个人填了 xm,就查出这个xm的所有个人资料在a中,如果选了b中money也能找出a中符合money值的数据,如果选了b中zt,c中msxx还是可以找到a中符合要求的个人信息。我这样写的: select aa.uid,aa.xm,aa.xb,aa.age,aa.sj,aa.qq,bb,uid,bb.money,bb.zt,cc.uid,cc.tdate,cc.msxx from a as aa,b as bb,c as cc where aa.uid=bb.uid or aa.uid=cc.uid or aa.uid=cc.uid;--------当然这里还需要加上另一个查询条件,我不知道该怎么写这个查询了,无论怎么写查出的都是空这样写的结果只出来4条,实际上应该是22条。
解决方案 »
- 复制一个数据库表中的多条记录到另一个数据库相同的表中问题
- SQL怎样实现行列互换?
- wangtiecheng(cappuccino)进来,就"如何获取最相近时间的值"之帖再次请教!
- asp怎么样读timestamp的时间呢
- sql语句,详情请进。
- 怪事请教:为什么执行LOCK_ESCALATION设置命令老出错?
- 类型不匹配的问题
- SQL Server 2005 附加上去的数据库为只读状态,怎么改成可以读写状态?
- 高分请教,返回记录集某个区间的记录是怎么写的?
- 将俩个同结构的同关键字的表的纪录更新,即用一个纪录替换另一个纪录,关键字段为第一个字段,请问各路高手(包括笨奔先生)该如何解决?谢谢帮忙。
- 【帮助】 关于分页存储
- 求助,我怎么从Sql数据库中取出job是 "客服/行政/前台" 的内容?
declare @a table(uid int,xm varchar(12),xb char(2),age int,sj varchar(12),qq varchar(15))
declare @b table(uid int,money decimal(10,2),zt varchar(12))
declare @c table(uid int,tdate datetime,msxx varchar(12))insert @a select
1,'张三','男',29,'13813990000','1231414' union all select
2,'张按时','女',25,'42340000','fsdf14' union all select
3,'果然三','男',22,'ffff00fff','ggggg14'insert @b select
2,5511.46,'工资'union all select
1,1515.4,'奖金'union all select
3,3155.5,'工资'
insert @c select
1,'2009-08-01','asf as 'union all select
2,'2009-04-21','fsfsf'union all select
3,'2009-06-30','sgsg'select a.* from @a a
join @b b on a.uid=b.uid
join @c c on a.uid=c.uid
where xm='张三'or money=1515.4 or zt='奖金' or msxx='sgsg'uid xm xb age sj qq
----------- ------------ ---- ----------- ------------ ---------------
1 张三 男 29 13813990000 1231414
3 果然三 男 22 ffff00fff ggggg14(所影响的行数为 2 行)
select * from a ,b ,c where a.uid=b.uid and b.uid=c.uid and money="XXX"
UNION
select a.* from @a a
join @b b on a.uid=b.uid
join @c c on a.uid=c.uid
where money=1515.4 or zt='奖金' or msxx='sgsg'uid xm xb age sj qq
----------- ------------ ---- ----------- ------------ ---------------
1 张三 男 29 13813990000 1231414
3 果然三 男 22 ffff00fff ggggg14(所影响的行数为 2 行)
join @b b on a.uid=b.uid
join @c c on a.uid=c.uid
这个是不可能成立的~~~~~~
-- 好多东西,只要稍加修改,就可以运用
declare @a table(uid int,xm varchar(12),xb char(2),age int,sj varchar(12),qq varchar(15))
declare @b table(uid int,money decimal(10,2),zt varchar(12))
declare @c table(uid int,tdate datetime,msxx varchar(12))insert @a select
1,'张三','男',29,'13813990000','1231414' union all select
2,'张按时','女',25,'42340000','fsdf14' union all select
3,'果然三','男',22,'ffff00fff','ggggg14'select * from @a WHERE xm='张三'
UNION
select a.* from @a a
join @b b on a.uid=b.uid
join @c c on a.uid=c.uid
where money=1515.4 or zt='奖金' or msxx='sgsg'