[为了增加解答的机率,我不得不重复发一条] 在两个表间进行 SELECT 操作的 问题,我想了一天都没有结果,很急阿,恳请请各位高手帮忙解决

LEO0071983 2006-09-04 03:32:02
下面是我的两个表

表一:
Chapter node isopen
1 NULL 1
1 1 1
1 2 0
2 1 0
3 NULL 1
3 1 0
....

表二
id Chapter node
1001 1 Null
1002 1 Null
1008 1 1
1009 1 1
1010 2 1
1011 2 1
1012 2 1
1013 2 1
1014 2 1
....
我想最终获得这样一个表
id Chapter node
1001 1 Null
1002 1 Null
1008 1 1
1009 1 1

即:根据 表二中每一条记录的chapter 和 node ,找到表一中的相应的行,如果 isopen = 1,
则 将表二中该行保留
============================
恳请各位高手帮帮忙啊!
小弟 万分感谢!
...全文
276 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
insnowind 2006-09-04
  • 打赏
  • 举报
回复
解决了就散点分,嘿嘿!!!
LEO0071983 2006-09-04
  • 打赏
  • 举报
回复
谢谢 rea1gz !我很欣赏您写的sql结构,很整洁优美
我原来的代码如下
select a.* from 表二 a,表一 b
where
(a.Chapter=b.Chapter and a.node=b.node)
or
(a.Chapter=b.Chapter and a.node is null and b.node is null)
and
b.isopen=1

但是总是得不到想要的结果!

谢谢 wangtiecheng 在你那我学到了 isnull地用法,我在实际应用中很需要这个函数
=========
一开机就看到问题被解决了,真是高兴啊!
谢谢每一个人
bugchen888 2006-09-04
  • 打赏
  • 举报
回复
SELECT b.*
FROM [表二] b, [表一] a
WHERE b.Chapter=a.Chapter
AND b.node=a.node
AND a.isopen=1
fxf66 2006-09-04
  • 打赏
  • 举报
回复
create table t1(Chapter int,node int,isopen int)
create table t2(id int,Chapter int,node int)

insert into t1
select 1,null,1 union all
select 1,1,1 union all
select 1,2,0 union all
select 2,1,0 union all
select 3,null,1 union all
select 3,1,0

insert into t2
select 1001,1,null union all
select 1002,1,null union all
select 1008,1,1 union all
select 1009,1,1 union all
select 1010,2,1

select * from t1
select * from t2

select b.*
from t1 a,t2 b
where a.chapter=b.chapter
and a.isopen=1
and (a.node =b.node or (a.node is null and b.node is null))

drop table t1,t2
rea1gz 2006-09-04
  • 打赏
  • 举报
回复
同理
isnull(A.node,0)=isnull(B.node,0)
rea1gz 2006-09-04
  • 打赏
  • 举报
回复
isnull(a.node,0)=isnull(b.node,0)
是不对的
因为a.node=null b.node=''是不应该认为相等的

冒牌有时候就是这么讨厌的吹毛求疵,呵呵
xyxfly 2006-09-04
  • 打赏
  • 举报
回复
select B.* from 表一 A inner join 表二 B on A.chapter=B.chapter and isnull(A.node,0)=isnull(B.node,0) where A.isopen=1

楼主没有试试上面各位给的答案呀? 怎么开两个贴...
chyliu 2006-09-04
  • 打赏
  • 举报
回复
select B.* from
表一 as A,表二 as B
Where A.Chapter = B.Chapter and
Isnull(A.node,'') = Isnull(B,node,'') and
A.isopen = 1
vovo2000 2006-09-04
  • 打赏
  • 举报
回复
select a.*
from 表二 a join 表一 b
on
a.Chapter=b.Chapter
and IsNull(a.node,0)=IsNull(b.node,0)
where
b.isopen=1
OracleRoob 2006-09-04
  • 打赏
  • 举报
回复
--改

select b.*
from 表一 a inner join 表二 b on a.chapter=b.chapter and isnull(a.node,0)=isnull(b.node,0)
where A.isopen=1
OracleRoob 2006-09-04
  • 打赏
  • 举报
回复
select b.*
from 表一 a inner join 表二 b on a.chapter=b.chapter and isnull(a.node,0)=isnull(b.node,0)
where b.isopen=1
OracleRoob 2006-09-04
  • 打赏
  • 举报
回复
select a.*
from 表一 a inner join 表二 b on a.chapter=b.chapter and isnull(a.node,'')=isnull(b.node,'')
where b.isopen=1
rea1gz 2006-09-04
  • 打赏
  • 举报
回复
select a.* from 表二 a,表一 b
where a.Chapter=b.Chapter
and (a.node=b.node or
(a.node is null and b.node is null)
)
and b.isopen=1

内容概要:本文围绕基于Basisformer模型的时间序列锂离子电池SOC(State of Charge,荷电状态)预测展开研究,利用PyTorch框架实现深度学习模型的构建与训练。通过将历史充放电数据作为输入,Basisformer能够有效捕捉电池状态的动态变化特征,提升SOC预测精度。文中详细介绍了模型结构设计、数据预处理流程、训练策略及实验结果分析,并与传统方法进行对比,验证了该方法在复杂工况下的优越性与鲁棒性。该研究不仅展示了Basisformer在时序建模中的潜力,也为电池管理系统提供了高精度的状态估计解决方案。; 适合人群:具备一定Python编程基础和深度学习理论知识,熟悉PyTorch框架,从事电池管理系统、新能源汽车或智能预测方向研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于电动汽车、储能系统等领域的电池SOC高精度实时估算;②为电池健康管理(BMS)提供可靠的状态输入;③推动深度学习在时间序列预测中的实际落地,提升现有预测模型的泛化能力与稳定性; 阅读建议:建议读者结合标题为【锂电池SOC估计】【PyTorch】基于Basisformer时间序列锂离子电池SOC预测研究(python代码实现)的资源,重点研读所提供的Python代码,深入理解数据处理方式与模型网络结构的设计思路,尝试调整超参数以观察对预测性能的影响,从而全面掌握Basisformer在时序建模中的优势、适用边界及工程化实现路径。

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧