发布网友 发布时间:2022-04-11 03:39
共3个回答
热心网友 时间:2022-04-11 05:09
oracle 数据库:
排序使用分析函数 : row_number() OVER ()
SELECT
row_number() OVER (partition BY t.trandate ORDER BY t.tranamt) "NO",
t.trandate,
nvl(t.tranamt,'小计'),
DECODE( COUNT(*),'1','', COUNT(*)) "计数",
decode(SUM(to_number(t.tranamt)),to_number(t.tranamt),'',SUM(to_number(t.tranamt)))"小计"
FROM testtable t GROUP BY rollup (trandate,tranamt) ;
热心网友 时间:2022-04-11 06:27
环境:Oracle 11g
SELECT CASE
WHEN COUNT=1 THEN trandate
WHEN COUNT > 1 AND trandate IS NULL THEN 'GLOBAL TOTAL '
WHEN COUNT > 1 AND trandate IS NOT NULL THEN 'TOTAL '||COUNT
END AS trandate,tranamt FROM
(
SELECT count(trandate) COUNT,
trandate,SUM(tranamt) tranamt FROM TESTTABLE GROUP BY ROLLUP(trandate,tranamt)
) t
热心网友 时间:2022-04-11 08:01
我的数据库,希望能帮到你