本文介绍了如何将逗号分隔的ID发送到SQL查询并在单行中获取相应的项(以逗号分隔)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下表格
tbl_items-> ID,名称,价格
tbl_customers->客户编号,客户名称
tbl_sales-> Id,custId,Itemlist,总价

我有一个proc可以将每个客户购买的商品的记录存储在一行中.
例如,如果客户(custID = 1001)购买了3个商品(商品ID 1,2,3),则该记录将存储在tbl_sales中的一行中,作为
1〜1001〜1,2,3〜价格的总和

现在我要显示的是这样的记录

客户名称"〜"item1,item2,item3"〜$ 600.

我怎么能得到这个.
我已经尝试过

i have following tables
tbl_items--> ID,name,price
tbl_customers--> CustId,custname
tbl_sales--> Id,custId,Itemlist,totalprice

I have a proc that stores the record of items bought by each customer in a single row
for eg if customer(custID=1001) buys 3 items(item id 1,2,3) then the record is stored in a single row in tbl_sales as
1~ 1001~ 1,2,3 ~sum of price

now what i want is to show this record like

"customername" ~ "item1,item2,item3" ~ $600.

how can i get this.
i have tried

select cus.name,amt.billamount,(select name form tbl_items where ID in cus.Itemlist)
 from tbl_customers cus join tbl_daily_sales_amount amt
 on cus.customerId=amt.customerID



等等..但是我无法得到rdesired输出
请帮我解决这个问题.



an so on.. but i cant get the rdesired output
pls help me with this.

推荐答案

select cus.name,amt.billamount,(select name form tbl_items where ID in cus.Itemlist)
 from tbl_customers cus join tbl_daily_sales_amount amt
 on cus.customerId=amt.customerID



等等..但是我无法得到rdesired输出
请帮助我.



an so on.. but i cant get the rdesired output
pls help me with this.



这篇关于如何将逗号分隔的ID发送到SQL查询并在单行中获取相应的项(以逗号分隔)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 04:46