我需要以“电子表格”类型的方式显示数据库中的数据,值垂直显示,而不是像通常那样水平显示为行。
网格需要正好是 16 列乘 12 行。在正常情况下,它将是两列,最多 96 行。
我从 ClearLogic 的答案中得出的查询:
..非常接近,但它生成了 15 列,并添加了两次值。它看起来足够近,让我想继续沿着这条路走下去。
注意:Val1 始终是 1..96 之间的值
我的 sql(产生 16 列乘 15 行的结果集)是:
Select Val1 AS col1, Val2 AS col2,NULL AS Col3,NULL AS Col4 ,NULL AS
Col5,NULL AS Col6,NULL AS col7,NULL AS Col8, NULL AS Col9, NULL AS Col10, NULL AS
Col11, NULL AS Col12, NULL AS Col13, NULL AS Col14, NULL AS Col15, NULL AS Col16
from PLATYPUSAVAILABILITY where Val1 < 13 and PLATYPUSID = 42
AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2,Val1 AS Col3, Val2 AS Col4,NULL
AS Col5,NULL AS Col6,NULL AS col7,NULL AS Col8, NULL AS Col9, NULL AS Col10, NULL AS
Col11, NULL AS Col12, NULL AS Col13, NULL AS Col14, NULL AS Col15, NULL AS Col16
from PLATYPUSAVAILABILITY where Val1 > 12 and Val1 < 25 and
PLATYPUSID = 42 AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2 ,NULL AS Col3, NULL AS Col4,Val1 AS
Col5, Val2 AS Col6,NULL AS col7,NULL AS Col8, NULL AS Col9, NULL AS Col10, NULL
AS Col11, NULL AS Col12, NULL AS Col13, NULL AS Col14, NULL AS Col15, NULL AS Col16
from PLATYPUSAVAILABILITY where Val1 > 24 and Val1 < 37 and
PLATYPUSID = 42 AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2 ,NULL AS Col3, NULL AS Col4, NULL AS
Col5, NULL AS Col6,Val1 AS col7,Val2 AS Col8, NULL AS Col9, NULL AS
Col10, NULL AS Col11, NULL AS Col12, NULL AS Col13, NULL AS Col14, NULL AS Col15,
NULL AS Col16 from PLATYPUSAVAILABILITY where Val1 > 36 and Val1
< 49 and PLATYPUSID = 42 AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2 ,NULL AS Col3, NULL AS Col4,Val1 AS
Col5,Val2 AS Col6,NULL AS col7,NULL AS Col8, Val1 AS Col9, Val2 AS
Col10, NULL AS Col11, NULL AS Col12, NULL AS Col13, NULL AS Col14, NULL AS Col15,
NULL AS Col16 from PLATYPUSAVAILABILITY where Val1 > 48 and Val1
< 61 and PLATYPUSID = 42 AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2 ,NULL AS Col3, NULL AS Col4,NULL AS
Col5,NULL AS Col6,NULL AS col7,NULL AS Col8, NULL AS Col9, NULL AS Col10,
Val1 AS Col11, Val2 AS Col12, NULL AS Col13, NULL AS Col14, NULL AS
Col15, NULL AS Col16 from PLATYPUSAVAILABILITY where Val1 > 60 and
Val1 < 73 and PLATYPUSID = 42 AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2 ,NULL AS Col3, NULL AS Col4,NULL AS
Col5,NULL AS Col6,NULL AS col7,NULL AS Col8, NULL AS Col9, NULL AS Col10, NULL AS
Col11, NULL AS Col12, Val1 AS Col13, Val2 AS Col14, NULL AS Col15, NULL
AS Col16 from PLATYPUSAVAILABILITY where Val1 > 72 and Val1 < 85
and PLATYPUSID = 42 AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
UNION select NULL AS col1,NULL AS col2 ,NULL AS Col3, NULL AS Col4,NULL AS
Col5,NULL AS Col6,NULL AS col7,NULL AS Col8, NULL AS Col9, NULL AS Col10, NULL AS
Col11, NULL AS Col12, NULL AS Col13, NULL AS Col14, Val1 AS Col15, Val2
AS Col16 from PLATYPUSAVAILABILITY where Val1 > 84 and PLATYPUSID = 42
AND AVAILABLEDATE = to_date('20120823', 'yyyymmdd')
我怎样才能让它自己限制在 12 行而不是溢出到 15 行?
我在 TOAD 中运行此查询后看到的屏幕截图可以在以下位置看到:
http://warbler.posterous.com/so-close-and-yet-so-far-away-sqlizers-lament
应该只有 12 行,并且值应该从第 9 列和第 10 列的顶部开始,并溢出到第 11 列和第 12 列的一行(顶部)。
我使用 Datagridview 作为标签,因为这是数据的最终目标:datagridview1.DataSource = //query result as OracleDataTable
更新
得到它的工作。请参阅是否可以使用交替的垂直列填充 DataGridView?