我必须在Crystal报表和VB报表中生成一个报表,其中数据库是Oracle,如附带的屏幕截图:
我使用了以下查询并获得了如下屏幕截图的输出:
SELECT ins.ins, ins.ins_name, crdi.ct, crdi.bin,
(select count(*) from crdh where crd_st='CN') as CNcount, (select count(*)
from crdh where crd_st='PO') as POcount
FROM crdh, crdi, ins
where crdh.bn=crdi.bn and crdi.ins=ins.ins and crdh.crd_st IN ('PO','CN')
GROUP BY ins.ins, crdi.bn, ins.ins_name,crdi
ORDER BY ins.ins, crdi.bn;
我有以下问题:
我运行了以下查询并获得了如下屏幕截图
的输出SELECT ins.ins_name,ins.ins,
crdi.crd_st, crdi.bin, crdh.crd_st,
COUNT(crdh.crd_st) as count
FROM crdh, crdi, ins
WHERE crdh.crd_st IN ('PO','CN') and crdi.bn in
(select unique bn from crdh)and crdh.bn=crdi.bn and
crdi.ins=ins.ins
GROUP BY ins.ins, crdi.bn, ins.ins_name,
crdi.crd_st,crdh.crd_st
ORDER BY ins.ins, crdi.bn;
我想将count列显示为报告中各行bn的一行。
我有Oracle 10g数据库并遵循以下链接
并进行以下查询并得到'ORA-00933:SQL命令未正确结束'错误。
SELECT bn, CNCount, POCount
FROM (
SELECT bn,
crd_st,
ROW_NUMBER() OVER (PARTITION BY bn ORDER BY crd_st) AS cardRank
FROM cardholder
)
pivot( count(crd_st) FOR cardRank IN ('CN' as CNCount, 'PO' as POCount));
提前感谢您的帮助。
答案 0 :(得分:1)
由于你得到了一些输出,现在根据需要设计输出,使用水晶报告中的交叉表。
bn
。@Count
并在该公式中只编写"Count"
并在行中使用公式。Count
。让我知道它是怎么回事
编辑---------------------------------------------- ----------------------------------------
1. Drag the crosstab on to report.
2. `Right click` on crosstab and go to `Crosstab expert`
3. There you will find 3 options, `Rows`, `Columns` and `Summarized fileds`
4. place the field what you want in row, place the filed what you want in column and same way place the column for summarized fields
答案 1 :(得分:1)
我通过运行以下查询获得了所需的输出:
SELECT ins.ins_name,ins.ins,crdi.ct, crdi.bn,
sum(DECODE(cardh.crd_st, 'PO', 1, 0)) POCount,
sum(DECODE(cardh.crd_st, 'CN', 1, 0)) CNCount
FROM crdh, crdi, ins
WHERE crdh.crd_st IN ('PO','CN') and crdi.bn in
(select unique bn from crdh)and crdh.bn=crdi.bn and
crdi.ins=ins.ins
GROUP BY ins.ins, crdi.bn, ins.ins_name,crdi.ct
ORDER BY ins.ins, crdi.bn;