查询以显示按项目分隔的数据 [英] query to display data seprated by items

查看:55
本文介绍了查询以显示按项目分隔的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要这样的输出

I want output like this

item_type:
Vegetables 
itemNumber  ItemName   quantity   price
101         Potato      10       20.00
102         Tomato     102       10.00
item_type:
Fruits:
itemNumber  ItemName   quantity   price
 103        Mango       2         30.00
 104        Apple       4         40.00



我尝试了以下查询



I tried the following query

select item_number,item_type,item_name ,quantity ,price from purchase_order order by item_type;



但输出是这样的



but the output is like this

item_number	item_type	item_name	quantity	price
3	   	fruits	         Dates          3	        57.900
6	        fruits		 Jackfruit      34              10.890	
1	        vegetables       Ladies Finger	23	        45.000
3	        vegetables       Broad Beans	23	        53.900




我尝试了bt组,它需要聚合功能

给我一个想法,如何获取该输出




I tried group by clause bt it needs aggregate function

give me an idea how to do get that output

推荐答案

查询是完全正确的!您需要更改字段的顺序:
Query is totally correct! You need to change the order of fields:
SELECT item_type, item_number, item_name, quantity ,price
FROM purchase_order
ORDER BY item_type



您要按item_type对记录进行分组,则需要使用报告来获得此功能.
使用其功能组逐步创建Crystal Report,图形,交叉表和子报表 [ ^ ]
ReportViewer [



You you want to group records by item_type, you need to use reports to get this functionallity.
Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report[^]
ReportViewer[^]


在您的项目类型中创建存储过程send参数并显示它.


ALTER PROCEDURE采购订单
@ItemType字符串
AS
开始
从PaymentLedger中选择itemno,itemname,qualityprice作为Balance
WHERE ItemType = @ItemType

END
u create stored procedure send parameter in ur item type and display it.


ALTER PROCEDURE purchase_order
@ItemType string
AS
BEGIN
select itemno, itemname, qualityprice as Balance from PaymentLedger
WHERE ItemType = @ItemType

END


将分组依据添加到item_type,以便根据item_type
add group by to item_type so you will get item list according to item_type


这篇关于查询以显示按项目分隔的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆