帆软FCP第二题:数据库中有一张地区数据统计表,但是并不规则

该博客讲述了如何处理数据库中不规则的地区数据统计表,包括地区缺位、时间缺位的情况。通过SQL语句进行数据清洗,将地区、分类、数量和日期提取并转换,最终达到统计每个地区在指定日期范围内的分类数据。涉及到的SQL操作包括数据过滤、缺失值处理和格式调整。
摘要由CSDN通过智能技术生成

【题目要求】

数据库中有一张地区数据统计表,但是并不规则 ,记录类似于,225100:02:3:20160725是一串代码,以:分割,第1位为地区代码,第2位为分类代码,第3位为数量,第4位为日期

地区代码含义225100-上海  225200-江苏  225300-浙江 为可能有某些位不存在,缺位时计算规则如下:

1、地区缺位时不参与统计

2、时间缺位时按20151220来计算

数据如下

现要求输入开始日期和结束日期后,自动统计这个时间段内每个地区和各个分类下的数据情况。日期控件中输入的日期格式要求为yyyy-MM-dd

【数据来源】考试数据库wubmh0及chq3g4表

【效果图参考】

        

 第一步:需要将地区缺位的数据去掉以及将时间缺位的数据补上日期,所以这里SQL语句应该这么写:

select substr(part, 0, instr(part, ':')) as area, substr(part, 8, 2) as category ,substr(part, length(part)-7, 8) as time,substr(part, 11, length(part)-19) as amount,part from 
(select 11 as id,  substr(part, 0, instr(part, ';')) as part from chq3g4 where id=1
UNION  ALL
select 12 as id,  substr(part, instr(part, ';')+1) as part from chq3g4 where id=1
UNION  ALL
select id,part from chq3g4  where id != 4 and  id !=8 and id != 1
UNION  ALL 
select  id,'225300:02:14:20151220' as part from chq3g4 where id = 8)

第一部分就是括号里的SQL语句:

select 11 as id,  substr(part, 0, instr(part, ';')) as part from chq3g4 where id=1
UNION  ALL
select 12 as id,  substr(part, instr(part, ';')+1) as part from chq3g4 where id=1
UNION  ALL
select id,part from chq3g4  where id != 4 and  id !=8 and id != 1
UNION  ALL 
select  id,'225300:02:14:20151220' as part from chq3g4 where id = 8
select 11 as id,  substr(part, 0, instr(part, ';')) as part from chq3g4 where id=1

这一句就是将

上图画线的地方提取出来 ,结果为:

第二局:

select 12 as id,  substr(part, instr(part, ';')+1) as part from chq3g4 where id=1

 这一句是将

图上画线的地方提取出来,结果为:

第三句:


select id,part from chq3g4  where id != 4 and  id !=8 and id != 1

这是将不符合要求的去掉,区域没有,时间没有,第一句有两个数据的。结果为:

第四句:

select  id,'225300:02:14:20151220' as part from chq3g4 where id = 8

 这一句是将

图上数据丢失的时间补上。结果为: 

然后将这四句的结果全部加起来,得到:

现在需要将part字段里的区域,分类,数量,日期都单独用列表示出来。

select substr(part, 0, instr(part, ':')) as area, substr(part, 8, 2) as category ,substr(part, length(part)-7, 8) as time,substr(part, 11, length(part)-19) as amount,part from 前面四个加起来的结果

 通过substr函数来截取part的各个部分,最后得到结果

最后一步还需要将category中的02,01,03分别改成分类02,分类01,分类03,

最后的SQL语句为:

结果为:

由于本题的参数的格式是2022-10-21这种格式,所以还需要将time字段格式在调整。需要将

substr(part, length(part)-7, 8)

改成:

(substr(part, length(part)-7, 4) || '-' || substr(part, length(part)-3, 2) || '-' || substr(part, length(part)-1, 2)) as time

预览结果为:

 最后将查询参数加到SQL语句上:

下一步:制作模板:

 

 最终效果:

下面是文档化的源代码设计与调试过程: 1. 首先,我们需要了解fcp命令的基本功能和使用方式。根据目中的要求,fcp命令的基本功能是复制源文件到目标文件。具体的接口为:[d:][path] fcp <source> [target]。 2. 在开始编写代码之前,我们需要先思考一下整个程序的框架。根据目中的要求,fcp命令需要支持两种操作:复制文件和显示帮助信息。因此,我们可以根据用户输入的参数来判断用户需要进行哪种操作。具体的代码框架如下: ``` if(args.length == 1 && args[0].equals("/?")) { // 显示帮助信息 } else if(args.length == 2) { // 复制文件 } else { // 参数错误,显示帮助信息 } ``` 3. 接下来,我们需要编写复制文件的代码。具体的实现方式是通过Java IO中的File类来读取源文件的内容,并将其写入目标文件中。代码如下: ``` File sourceFile = new File(args[0]); File targetFile = new File(args[1]); try ( FileInputStream inputStream = new FileInputStream(sourceFile); FileOutputStream outputStream = new FileOutputStream(targetFile); ) { byte[] buffer = new byte[1024]; int len; while((len = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } System.out.println("文件复制成功!"); } catch(IOException e) { System.out.println("文件复制失败:" + e.getMessage()); } ``` 4. 最后,我们需要编写显示帮助信息的代码。具体的实现方式是通过System.out.println()方法来输出一些提示信息。代码如下: ``` System.out.println("用法:fcp <source> [target]"); System.out.println("将源文件参数source指定的文件复制到目标参数target标识的目标文件中。"); System.out.println("如果行命令fcp后面只有一个参数“/?”,则显示命令的使用格式及详细说明。"); ``` 5. 至此,整个fcp命令的代码设计就完成了。我们可以在命令行中输入以下命令来测试它的功能: ``` fcp source.txt target.txt fcp /? ``` 6. 经过测试,我们发现fcp命令的功能正常,可以正常地复制文件和显示帮助信息。 以上就是fcp命令的源代码设计与调试过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帆软爱好者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值