跪求一个超难的ORACLE数据纵向存储转成横向查询输出

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跪求一个超难的ORACLE数据纵向存储转成横向查询输出相关的知识,希望对你有一定的参考价值。

跪求一个超难的ORACLE数据纵向存储转成横向查询输出
我在ORACLE数据库中建有以下四张表,用来存储设备的基本信息,存储型式为纵向存储方式。

设备表:bd_sbtz_gg

编号(sbbh) 设备名称(sbmc) 设备类型(lxbh)
1 所内变压器 101
2 真空断路器 102
3 电磁式CT 103
4 电容式CT 104

设备类型表:(bm_sblx)

编号(lxbh) 类型名称(lxmc)
101 变压器
102 断路器
103 电磁是电压互感器
104 电容式电压互感器

设备属性表:(bm_sbsx)

属性编号(sxbh) 设备类型(lxbh) 属性名称(sxmc)
201 101 电压等级
202 102 电压等级
203 103 电压等级
204 104 电压等级
205 101 产地
206 102 产地
207 103 产地
208 104 产地
209 104 维护人

设备属性值表:(bm_sbsxz)

编号(sxzbh) 所属设备(sbbh) 属性编号(sxbh) 属性值(sxz)
301 1 201 220
302 1 205 沈阳
303 2 202 66
304 2 206 长春
305 3 203 220
306 3 207 四平
307 4 204 220
308 4 208 四平
309 4 209 张某

现想将此四张表进行横向查询输出:

查询结果型式为:

设备编号 设备名称 设备类型 电压等级 产地 维护人
101 所内变压器 变压器 220 沈阳
102 真空断路器 断路器 66 长春
103 电磁式CT 电磁是电压互感器 220 四平
104 电容式CT 电容式电压互感器 220 四平 张某

--先建立四个表,并向表中插入数据
create table temp_bd_sbtz_gg
(
sbbh varchar2(20),
sbmc varchar2(20),
lxbh varchar2(20)
)
insert into temp_bd_sbtz_gg values('1','所内变压器','101');
insert into temp_bd_sbtz_gg values('2','真空断路器','102');
insert into temp_bd_sbtz_gg values('3','电磁式CT','103');
insert into temp_bd_sbtz_gg values('4','电容式CT','104');
commit;

create table temp_bm_sblx
(lxbh varchar2(20),
lxmc varchar2(20))
insert into temp_bm_sblx values('101','变压器');
insert into temp_bm_sblx values('102','断路器');
insert into temp_bm_sblx values('103','电磁式电压互感器');
insert into temp_bm_sblx values('104','电容式电压互感器');
commit;

create table temp_bm_sbsx
(
sxbh varchar2(20),
lxbh varchar2(20),
sxmc varchar2(20)
)

insert into temp_bm_sbsx values('201','101','电压等级');
insert into temp_bm_sbsx values('202','102','电压等级');
insert into temp_bm_sbsx values('203','103','电压等级');
insert into temp_bm_sbsx values('204','104','电压等级');
insert into temp_bm_sbsx values('205','101','产地');
insert into temp_bm_sbsx values('206','102','产地');
insert into temp_bm_sbsx values('207','103','产地');
insert into temp_bm_sbsx values('208','104','产地');
insert into temp_bm_sbsx values('209','104','维护人');
commit;

create table temp_bm_sbsxz
(sxzbh varchar2(20),
sbbh varchar2(20),
sxbh varchar2(20),
sxz varchar2(20))

insert into temp_bm_sbsxz values('301','1','201','220');
insert into temp_bm_sbsxz values('302','1','205','沈阳');
insert into temp_bm_sbsxz values('303','2','202','66');
insert into temp_bm_sbsxz values('304','2','206','长春');
insert into temp_bm_sbsxz values('305','3','203','220');
insert into temp_bm_sbsxz values('306','3','207','四平');
insert into temp_bm_sbsxz values('307','4','204','220');
insert into temp_bm_sbsxz values('308','4','208','四平');
insert into temp_bm_sbsxz values('309','4','209','张某');
commit;

create table temp_jieguo
(
bh varchar2(20),
name varchar2(20),
type varchar2(20),
lever varchar2(20),
address varchar2(20),
person varchar2(20)
)

--纵横转换的存储过程
create or replace procedure p_temp_change is
sql_1 long;
begin
sql_1 := 'truncate table temp_jieguo';
execute immediate sql_1;
commit;
insert into temp_jieguo
select b.lxbh,
a.sbmc,
b.lxmc,
max(decode(c.sxmc, '电压等级', d.sxz)),
max(decode(c.sxmc, '产地', d.sxz)),
max(decode(c.sxmc, '维护人', d.sxz))
from temp_bd_sbtz_gg a,
temp_bm_sblx b,
temp_bm_sbsx c,
temp_bm_sbsxz d
where c.sxbh = d.sxbh
and a.lxbh = b.lxbh
and a.lxbh = c.lxbh
group by b.lxbh, a.sbmc, b.lxmc;
commit;
end;
--运行
declare
begin
p_temp_change;
end;
--查看结果
select * from temp_jieguo;
参考技术A --建立视图1用来关联【设备表】和【设备类型表】
create or replace view view_1 as
select
a.sbbh as 设备编号,
a.sbmc as 设备名称,
b.lxbh as 设备类型编号,
b.lxmc as 设备类型
from
bd_sbtz_gg as a,
bm_sblx as b
where
a.lxbh=b.sxbh;
--建立视图2-1用来关联【视图1】和【设备属性表】把【电压等级编号】的值取出
create or replace view view_2_1 as
select
a.设备编号,
a.设备名称,
a.设备类型,
b.sxbh as 电压等级编号
from
view_1 as a,
bm_sbsx as b
where
a.设备类型编号=b.lxbh
and
b.sxmc='电压等级';
--建立视图2-2用来关联【视图1】和【设备属性表】把【产地编号】的值取出
create or replace view view_2_2 as
select
a.设备编号,
a.设备名称,
a.设备类型,
b.sxbh as 产地编号
from
view_1 as a,
bm_sbsx as b
where
a.设备类型编号=b.lxbh
and
b.sxmc='产地';
--建立视图2-3用来关联【视图1】和【设备属性表】把【维护人编号】的值取出
create or replace view view_2_3 as
select
a.设备编号,
a.设备名称,
a.设备类型,
b.sxbh as 维护人编号
from
view_1 as a,
bm_sbsx as b
where
a.设备类型编号=b.lxbh
and
b.sxmc='维护人';
--建立视图3-1用来关联【视图2-1】和【设备属性值表】把【电压等级】的值取出
create or repalce view view_3_1 as
select
a.设备编号,
a.设备名称,
a.设备类型,
b.sxz as 电压等级
from
view_2_1 as a,
bm_sbsxz as b
where
a.电压等级编号=b.sxbh
and
a.设备编号=b.sbbh;
--建立视图3-2用来关联【视图2-2】和【设备属性值表】把【产地】的值取出
create or repalce view view_3_2 as
select
a.设备编号,
a.设备名称,
a.设备类型,
b.sxz as 产地
from
view_2_1 as a,
bm_sbsxz as b
where
a.产地编号=b.sxbh
and
a.设备编号=b.sbbh;
--建立视图3-3用来关联【视图2-3】和【设备属性值表】把【维护人】的值取出
create or repalce view view_3_3 as
select
a.设备编号,
a.设备名称,
a.设备类型,
b.sxz as 维护人
from
view_2_1 as a,
bm_sbsxz as b
where
a.维护人编号=b.sxbh
and
a.设备编号=b.sbbh;
--联合视图3-1~3-3检索最终结果
select
a.设备编号,
a.设备名称,
a.设备类型,
a.电压等级,
b.产地,
c.维护人
from
view_3_1 as a,
view_3_2 as b,
view_3_3 as c
where
a.设备编号=b.设备编号
and
b.设备编号=c.设备编号;

如何在 CSS 中设置纵向和横向媒体查询?

【中文标题】如何在 CSS 中设置纵向和横向媒体查询?【英文标题】:How to set portrait and landscape media queries in css? 【发布时间】:2015-01-07 18:47:52 【问题描述】:

这是我的媒体查询:

@media screen and (min-device-width: 768px) and (max-device-width: 1824px) and (orientation : portrait)
  .hidden-desktop 
    display: inherit !important;
  
  .visible-desktop 
    display: none !important ;
  
  .visible-tablet 
    display: inherit !important;
  
  .hidden-tablet 
    display: none !important;
  


@media screen and (min-device-width: 768px) and (max-device-width: 1824px) and (orientation : landscape)
  .hidden-desktop 
    display: inherit !important;
  
  .visible-desktop 
    display: none !important ;
  
  .visible-tablet 
    display: inherit !important;
  
  .hidden-tablet 
    display: none !important;
  

@media screen and (max-device-width: 767px) and (orientation: portrait) 
  .hidden-desktop 
    display: inherit !important;
  
  .visible-desktop 
    display: none !important;
  
  .visible-phone 
    display: inherit !important;
  
  .hidden-phone 
    display: none !important;
  

@media screen and (max-device-width: 767px) and (orientation: landscape) 
  .hidden-desktop 
    display: inherit !important;
  
  .visible-desktop 
    display: none !important;
  
  .visible-phone 
    display: inherit !important;
  
  .hidden-phone 
    display: none !important;
  
 

但在平板电脑中,如果是横向模式,则显示此 div

 .visible-tablet 
    display: inherit !important;
  

如果是纵向模式,则显示此 div

.visible-phone 
    display: inherit !important;
  

我希望这个 div .visible-tablet 在我将平板电脑切换到自动旋转模式(用于纵向和横向)时始终显示

但是我使用了纵向和横向条件,但我仍然面临这个问题。有cmets吗?

【问题讨论】:

【参考方案1】:

iPad 媒体查询(所有代 - 包括 iPad mini)

感谢 Apple 致力于为用户创造一致的体验,并为开发人员提供轻松的时间,所有 5 款不同的 iPad(iPad 1-5 和 iPad mini)都可以通过一个 CSS 媒体查询来定位。接下来的几行代码应该非常适合响应式设计。

iPad 纵向和横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)   /* STYLES GO HERE */

iPad 横屏

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)  /* STYLES GO HERE */

iPad 纵向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait)  /* STYLES GO HERE */ 

iPad 3 和 4 媒体查询

如果您希望仅针对第 3 代和第 4 代 Retina iPad(或具有类似分辨率的平板电脑)为平板电脑的 Retina 显示屏添加 @2x 图形或其他功能,请使用以下媒体查询。

Retina iPad 纵向和横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 2)  /* STYLES GO HERE */

Retina iPad 横屏

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 2)  /* STYLES GO HERE */

Retina iPad 纵向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio: 2)  /* STYLES GO HERE */ 

iPad 1 和 2 媒体查询

如果您希望为较低分辨率的 iPad 显示器提供不同的图形或选择不同的排版,下面的媒体查询将在您的响应式设计中发挥作用!

iPad 1 和 2 纵向和横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (-webkit-min-device-pixel-ratio: 1) /* STYLES GO HERE */

iPad 1 和 2 横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 1)   /* STYLES GO HERE */

iPad 1 和 2 纵向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) 
and (-webkit-min-device-pixel-ratio: 1)  /* STYLES GO HERE */ 

来源:http://stephen.io/mediaqueries/

【讨论】:

你可以使用... css-tricks.com/snippets/css/media-queries-for-standard-devices min-device-widthmax-device-width are deprecated。 在设备上检查时最大设备宽度和最小设备宽度不起作用 问题不是询问 ipad 的媒体查询。它特别说明了纵向和横向,其中包括比 ipad 更多的设备。 Apple 用户在世界上只能看到 Apple 设备。这现在应该很明显了。根据他们的说法,世界上不应该存在其他设备。【参考方案2】:

可以这么简单。

@media (orientation: landscape) 


【讨论】:

请记住,这将适用于所有宽高比大​​于高的东西,也就是大多数现代屏幕。如果你对此很满意,那么这个媒体查询就是完美的。找到了这个代码笔,它证明了这一点:codepen.io/CrisMVP3200/pen/BmBaZy @srussking 您还期待什么其他行为? @korona 只是想明确一点,这将影响笔记本电脑屏幕以及手机/平板电脑。就我个人而言,我倾向于以移动方式来考虑风景和肖像,但这实际上只是比高更宽的任何东西...... 奇怪的是,这也适用于高度和宽度相等的设备(也就是方形屏幕)。

以上是关于跪求一个超难的ORACLE数据纵向存储转成横向查询输出的主要内容,如果未能解决你的问题,请参考以下文章

oracle 数据库sql高手来看看,如何纵向转横向

oracle中如何把横向表变为纵向表 函数是啥

ORACLE数据库如何将纵向数据改写成横行的?

oracle纵向数据变横向

超难的c语言组合问题

linux数据库表怎么纵向显示