返回首页

gbase数据、南大通用产品文档:GBase8ax86_64linuxglibc235295342targz 下载perl

更新日期:2024年09月11日

的安装包。
2, 从
http://mirrors.sohu.com/CPAN/authors/id/M/MJ/MJEVANS/DBD-ODBC-1.39.t
ar.gz 下载DBD-ODBC-1.39。
3, 安装perl-5.14。perl 默认安装在/opt/ActivePerl-5.14 目录下。
4, 安装DBD-ODBC-1.39,先解压DBD-ODBC-1.39.tar.gz,然后执行如下
命令安装:
/opt/ActivePerl-5.14/bin/perl Makefile.PL

GBase 8a 程序员手册ODBC 篇
南大通用数据技术股份有限公司

- 81 -
make
make install
5, 接下来是创建ODBC 数据源,
创建ODBC 数据源的方法请参考3.2.2。

果涉及到中文,那么一定要设置GBase 8a ODBC 驱动的字符集(该字符集需要
与集群安装时默认的字符集保持一致)
。此用例中GBase 8a ODBC 字符集设置为
UTF8。
#!/opt/ActivePerl-5.14/bin/perl
use DBI;
use encoding 'utf-8';

$dbh=DBI->connect('dbi:ODBC:gbase8a', 'gbase', 'gbase20110531');
my $sth=$dbh->prepare("drop table if exists t_plodbc");
$sth->execute();
my $sth=$dbh->prepare("create table t_plodbc(a varchar(100), b
int)");
$sth->execute();
my $sth=$dbh->prepare("insert into t_plodbc values('南大通用',
10)");
$sth->execute();
my $sth=$dbh->prepare("select * from t_plodbc");
$sth->execute();
while(@data=$sth->fetchrow_array())
{
print "$data[0]\n";
}

该版本兼容GBase8cV5_S3.0.0B110 版本,可实现平滑升级。

GROUP BY GROUPING SETS 函数
语法
GROUP BY GROUPING SETS( (…),(…),…)
功能
对GROUPING SETS 后面括号里的n 个字段或表达式分别做GROUP BY 操作,
最后将结果合并在一起。
详细解释
GROUP BY GROUPING SETS (A,B,C) (A、B、C 代表语法中的“(…)”)
首先对(A)进行GROUP BY,然后对(B)进行GROUP BY,然后对(C)进行GROUP
BY,最后将所有结果合并在一起(相当于UNION ALL 操作),如果n 个字段或
表达式中的一个或多个在某一分组中不出现在GROUP BY 后面,用NULL 代替
不出现的字段或表达式。
示例
示例中所用的表及数据:
DROP TABLE IF EXISTS t3;

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
884
CREATE TABLE t3 (color_type varchar(20),color_count int, in_date date);
INSERT INTO t3 (color_type,in_date,color_count)
VALUES('black','2010-09-11',18),
('black','2010-10-05',18),('black','2010-10-13',31),
('blue','2010-09-21',23),('blue','2010-09-30',15),
('blue','2010-10-11',62),('red','2010-09-12',41),
('red','2010-10-01',12),('red','2010-10-05',11);
示例1:GROUP BY GROUPING SETS(color_type,f_YearMonth)
gbase> SELECT color_type,in_date,color_count FROM t3 ORDER BY
color_type,in_date;
+------------+------------+-------------+
| color_type | in_date
| color_count |
+------------+------------+-------------+
| black
| 2010-09-11 |
18 |
| black
| 2010-10-05 |
18 |
| black
| 2010-10-13 |
31 |
| blue
| 2010-09-21 |
23 |
| blue
| 2010-09-30 |
15 |
| blue
| 2010-10-11 |
62 |
| red
| 2010-09-12 |
41 |
| red
| 2010-10-01 |
12 |
| red
| 2010-10-05 |
11 |
+------------+------------+-------------+
9 rows in set
gbase> SELECT NVL(color_type,'') as color_type_show,DECODE(color_ty
pe,NULL,f_YearMonth || '合计',NVL(f_YearMonth,color_type || ' 小计'))
AS f_YearMonth_show,SUM(color_count) FROM (SELECT color_type,DA
TE_FORMAT(in_date, '%Y-%m') as f_YearMonth,color_count FROM t3)
t GROUP BY GROUPING SETS(color_type,f_YearMonth) ORDER BY
color_type,f_YearMonth;
+-----------------+------------------+------------------+
| color_type_show | f_YearMonth_show | SUM(color_count) |
+-----------------+------------------+------------------+
| black
| black 小计
|
67 |
| blue
| blue 小计
|
100 |
| red
| red 小计
|
64 |
|
| 2010-09 合计
|
97 |
|
| 2010-10 合计
|
134 |
+-----------------+------------------+------------------+
5 rows in set

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
885