有这样两个表:
站点参数表AutoStationID,结构如下:
StationID, 站名数据表Rain_hour(每个站点每小时一条数据),结构如下:
StationID(与前面表对应), 雨量
平时往Rain_hour表中插入数据是这样操作的:如果某个StationID当前小时有数据并为0的话,则插入一条记录,其雨量为NULL,如果该StationID当前小时没有数据,则不插入记录。如今查询Rain_hour中遇到这样的问题:
想查询出某个StationID在某个时间段的数据,当然这其中肯定有某几个站点缺少数据的,
select
A.StationID,
A.站名,
B.雨量,
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'这样查询出来的话,数据为0的与没有数据的StationID里的雨量都会显示为NULL,有没有什么办法可以区分开?比如将原本NULL的数据显示为0,缺数据的改为////
?大师帮忙啦,很急呀~~~
站点参数表AutoStationID,结构如下:
StationID, 站名数据表Rain_hour(每个站点每小时一条数据),结构如下:
StationID(与前面表对应), 雨量
平时往Rain_hour表中插入数据是这样操作的:如果某个StationID当前小时有数据并为0的话,则插入一条记录,其雨量为NULL,如果该StationID当前小时没有数据,则不插入记录。如今查询Rain_hour中遇到这样的问题:
想查询出某个StationID在某个时间段的数据,当然这其中肯定有某几个站点缺少数据的,
select
A.StationID,
A.站名,
B.雨量,
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'这样查询出来的话,数据为0的与没有数据的StationID里的雨量都会显示为NULL,有没有什么办法可以区分开?比如将原本NULL的数据显示为0,缺数据的改为////
?大师帮忙啦,很急呀~~~
解决方案 »
- insert into HBTrigger_EnglishNews select id, 'Update', @updateFields from Inser
- 求救Sql问题
- 合计问题
- 有点困惑。希望给解答一下!!!!!
- 如何用一个备份文件恢复生成四个不同名的数据库(结构完全一样)谢谢!(在线等待)
- 如何将在sqlserver2000中建的数据库完整导入到另一机器的msde2000桌面版??
- 求 SQL 语句头疼的难题的 解决方法
- 关于sql数据库文件*.mdf和*.log大小的一些疑问
- 衔接服务器问题
- 这个汇总语句如何写?
- 求一条sql语句实现插入数据并返回这条记录的id
- 在连接Reporting Service时报错:此版本的 Reporting Service 不支持功能"将其他版本的Sql Server用于报表数据源和/或报表服务器数据库"
insert station values(8,'AAA')
insert station values(9,'BBB')
select * from stationcreate table Rain_hour(StationID int,雨量 int,观测时间 datetime)
insert Rain_hour
select 9,null,'2006-06-01 08:00:00'
select * from Rain_hour-- 比如将原本NULL的数据显示为0,缺数据的改为////
-- 楼主是什么意思,不太明白
select
A.StationID,
A.站名,
B.雨量
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'drop table station,Rain_hour
A.StationID,
A.站名,
isnull(B.雨量,0)
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'
StationID,
观测时间,
isnull(雨量,'')
from Rain_hour
where StationID=30102
and 观测时间>'2006-04-10 15:00:00'
and 观测时间<'2006-04-10 20:00:00'比如这样的语句,如果只有2条记录,那只能查询出2条数据来,如果其雨量为NULL,那则显示为0,这样用ISNULL(雨量,0)可以做到。
现在想将其他2条也显示出来,并且将其雨量设置为///,如何做?
A.StationID,
A.站名,
(case when b.站名 is null then '////' else b.雨量 end)[雨量]
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'
select
A.StationID,
A.站名,
(case when b.StationID is null then '////' else b.雨量 end)[雨量]
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'
select
A.StationID,
A.站名,
(case when b.StationID is null then '-1' else b.雨量 end)[雨量]
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'是你自己说要'////'的,呵呵.
那没有数据就写成-1,到时统计的时候判断一下,不是-1的就累加.如果你有统计总雨量需求的话.
select
A.StationID,
A.站名,
(case when b.StationID is null then '////' else isnull(b.雨量,0) end)[雨量]
from Station as A
left join Rain_hour as B
on A.StationID=B.StationID
where B.观测时间='2006-06-01 08:00:00'
==================================
= CSDN助手 全面支持CSDN论坛 =
= 监视、收藏、历史、签名走马灯 =
==================================