tnjk.net
当前位置:首页 >> 一个关于sql多表联合查询的问题 >>

一个关于sql多表联合查询的问题

假定3张表分别是normal_cus,vip_cus,ent_cus, 这3张表都包含字段:username, 可以这么写SQL: select username,'normal_cus' as tab_name from normal_cus where username='张三' union select username,'vip_cus' as tab_name from vip_cus whe...

SELECT I.Brand as 品牌,I.Type as 规格,S.num as 库存,S.Price as 库存均价,B.lastNum as 最后入库数,B.lastPrice as 最后入库价 from a I, c B,b S where I.id = B.id and I.id = S.id and LEFT(B.No,2)='CG' and T.Brand '' and T.num >0 and...

ID是TBALE1与TABLE2都有的字段,并且是相关联的字段 select * from table2 where id in (select id from table1 where 列1=2) where 你需要的条件

select t_cp.id, t_cp.proc, t_odid_cpid.num from t_odid_cpid left join t_cp on t_cp.id = t_odid_cpid.cpid left join T_ORDER on t_odid_cpid.odid = T_ORDER.odid

通过contract_project做中间表就行: select * from contract_project a left join project b on a.projectId = b.projectId left join contract c on a.contractId = c.contractId 前提是contract_project要大而全,包含所有的pid和cid,不然不行

带有中国的所有记录(ID=3时,只显示是中国的一条): select a.* from a inner join b on a.id=b.aid where b.tagname='中国' 只有有香港,所属ID全都不显示: select a.* from a inner join b on a.id=b.aid where b.tagname='中国' and not e...

你的这种写法不是联合查询,是合并查询,应该这样写: SELECT 员工信息表.员工编号,员工姓名,基本工资 FROM 员工信息表 INNER JOIN 员工工资表 ON 员工信息表.员工编号=员工工资表.员工编号 ORDER BY 员工信息表.员工编号

不知道是不是这个意思? select a.id , ---或者其他个人信息 count(d.xx_id),--应有考勤数量 sum(nvl(d.countid,0)) --实际考勤数量 from a , (select b.xx_id,count(c.id) countid from b,c where b.id = c.kj_id(+) group by b.xx_id ) d wher...

select * from love_questions t1 left join love_answers t2 on t1.id=t2.question_id left join love_answers_content t3 on t2.id=t3.answer_id

select t1.name, t1.comnum, t2.comaddfrom table1 as t1left join table2 as t2on t2.name = t1.name

网站首页 | 网站地图
All rights reserved Powered by www.tnjk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com