table
style
id type name
1 NK09 test1
2 NK10 test2
3 Nk22 test3
table2
goods
id type list
1 1 洗脸盆
2 1 毛巾
3 1 小毛巾
4 3 绳子
把table1与table2联合出来,得出这样的
id1 type name desc
1 NK09 test1 洗脸盆(1),毛巾(1),小毛巾(1)
2 NK10 test2
3 NK22 test3 绳子(3)
注意desc后面是货品的数量,若不能实现,也就算了,但,一定要显示出货品名来。
谢谢,在线等。
------解决方案--------------------
没看懂,是怎么关联出来的...为啥2 NK10 test2 没有呢?
------解决方案--------------------
怎么知道绳子是三条的?!没有道理哦
------解决方案--------------------
table1和table2的关联字段是哪个
------解决方案--------------------
select a.*,b.list from style a left join goods b on a.type=b.type
------解决方案--------------------
你的数量是从哪个列得到的
------解决方案--------------------
WITH A AS(
SELECT 1 AS ID, 'NK09' AS TYPE,'test1' AS NAME FROM DUAL UNION ALL
SELECT 2 AS ID, 'NK10' AS TYPE,'test2' AS NAME FROM DUAL UNION ALL
SELECT 3 AS ID, 'Nk22' AS TYPE,'test3' AS NAME FROM DUAL
), B AS(
SELECT 1 AS ID,1 AS TYPE,'洗脸盆' AS LIST FROM DUAL UNION ALL
SELECT 2 AS ID,1 AS TYPE,'毛巾' AS LIST FROM DUAL UNION ALL
SELECT 3 AS ID,1 AS TYPE,'小毛巾' AS LIST FROM DUAL UNION ALL
SELECT 4 AS ID,3 AS TYPE,'绳子' AS LIST FROM DUAL
)
SELECT ID,TYPE,NAME,TO_CHAR(WMSYS.WM_CONCAT(N))
FROM
(
SELECT A.ID,A.TYPE,A.NAME,B.LIST
------解决方案--------------------
'('
------解决方案--------------------
COUNT(LIST) OVER(PARTITION BY LIST)
------解决方案--------------------
')' AS N
FROM A,B
WHERE A.ID = B.TYPE
)
GROUP BY ID,TYPE,NAME
------解决方案--------------------
1 NK09 test1 毛巾(1),小毛巾(1),洗脸盆(1)
3 Nk22 test3 绳子(1)
------解决方案--------------------
擦...
原来中间那个也要显示... 那就