SQL Script to pull duplicate data

2019-08-30 17:47发布

Need help pointing in right direction using an SQL query to extract data out of this SYBASE database example:

12345  blue
12345  red
12345  green
56789  purple
56789  black
98765  brown

output must look like this:
12345 blue red green
56789 purple black
98765 brown

Was trying to use "union" or maybe "distinct" Please point me in the right direction.

标签: sql sybase-iq
1条回答
冷血范
2楼-- · 2019-08-30 18:26

Oracle uses WM_CONCAT or LIST_AGG to do this anymore I think sysbase uses List()

Source documentation describing function

So.. using your SQL

Select Field1, list(Field2)
FROM table
Group by Field1


SELECT item_loc.niin, list(item_loc.location_number)
FROM item_loc 
GROUP BY item_loc.niin

I just removed a space after list before the ( so List ( became List(

Now the nature of the error your getting indicates list isn't a function in your version of sybase... I'm still trying to find documentation on sybase 15.3 and proper syntax for it (or if it supports List)

查看更多
登录 后发表回答