string-aggregation

SQL Server equivalent to GROUP_CONCAT() [duplicate]

孤街醉人 提交于 2019-12-10 17:18:36
问题 This question already has answers here : Simulating group_concat MySQL function in Microsoft SQL Server 2005? (10 answers) Closed last year . I have this database: And I need to get the following data for each Client: Client Name Contract Name(s) Project(s) Employees who logged hours to a project from the first day of the current month until the last day of the current month Total number of hours logged for each employee during the month Employee rate Total Charges per employee (i.e. employee

How to find count and names of distinct characters in string in PL/SQL [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-07 10:20:45
问题 This question already has an answer here : How can I get the unique characters from a string in Oracle? (1 answer) Closed 6 years ago . I'm quite new to PL/SQL and I need to get the names and count of the distinct characters in a string. E.g. if I have a string str="helloexample" , I need to get output of distinct characters in str , i.e. heloxamp . How can I do this? 回答1: You can use regular expression as follows: SET serveroutput ON DECLARE str VARCHAR2(20):='helloexample'; str_length

Concatenate Over Oracle

只愿长相守 提交于 2019-12-07 07:54:58
问题 This is a sample table data Fruit Number Apple 1 Apple 2 Apple 3 Kiwi 6 Kiwi 10 I try to concatenate the table column values to get the following Fruit Number Apple 1-2-3 Kiwi 6-10 Is there a way to query this or store procedure? Something like Concatenate over(partition by) , I don't know much about stored procedures. Thanks! 回答1: OP is on Oracle 10g , and LISTAGG was introduced in 11g Release 2 . Therefore, in Oracle version prior to 11g where LISTAGG is not supported, you could use ROW

How to find count and names of distinct characters in string in PL/SQL [duplicate]

半世苍凉 提交于 2019-12-05 16:02:09
This question already has an answer here : How can I get the unique characters from a string in Oracle? (1 answer) Closed 6 years ago . I'm quite new to PL/SQL and I need to get the names and count of the distinct characters in a string. E.g. if I have a string str="helloexample" , I need to get output of distinct characters in str , i.e. heloxamp . How can I do this? You can use regular expression as follows: SET serveroutput ON DECLARE str VARCHAR2(20):='helloexample'; str_length NUMBER; c VARCHAR2(20):=NULL; d NUMBER; BEGIN str_length:=LENGTH(str); FOR i IN 1..str_length LOOP IF regexp

Concatenate Over Oracle

最后都变了- 提交于 2019-12-05 15:35:28
This is a sample table data Fruit Number Apple 1 Apple 2 Apple 3 Kiwi 6 Kiwi 10 I try to concatenate the table column values to get the following Fruit Number Apple 1-2-3 Kiwi 6-10 Is there a way to query this or store procedure? Something like Concatenate over(partition by) , I don't know much about stored procedures. Thanks! OP is on Oracle 10g , and LISTAGG was introduced in 11g Release 2 . Therefore, in Oracle version prior to 11g where LISTAGG is not supported, you could use ROW_NUMBER() and SYS_CONNECT_BY_PATH functions. SELECT fruit, LTRIM(MAX(SYS_CONNECT_BY_PATH(number,',')) KEEP

Oracle Function: Replicate wm_concat

前提是你 提交于 2019-12-05 11:57:19
I currently am working on a project within Crystal Reports that refuses to use the undocumented function WM_CONCAT, which is allowable within Oracle 10g. Here is the WM_CONCAT header information WM_CONCAT(p1 IN VARCHAR2) RETURN VARCHAR2 To use WM_CONCAT I pass it the following: WM_CONCAT(column1); This function seems to accept a column of type varchar2, and returns a comma delimited list of values from the column. I currently have a custom version of this function that works (on my work computer), but it is not optimal and lacks re-usability. Could anyone provide a good, re-usable function

Group_Concat with join equivalent in SQL SERVER

僤鯓⒐⒋嵵緔 提交于 2019-12-04 05:12:01
问题 I am having trouble in my code. I used to be on MySQL but I've migrated my codes into SQL Server. Now I am having trouble with this GROUP_CONCAT function. I found some 'potential' equivalent but it's just not resulting on what is expected. Here is the query: SELECT GROUP_CONCAT(c.namecheck SEPARATOR '; ') AS GROUPNAME FROM db_name a left JOIN db_employee b ON a.nameId = b.empID left join db_civ c ON b.nameNum = c.civNum I tried some. But as I've said, its does not output the result that what

String Aggregation in sqlite

最后都变了- 提交于 2019-12-03 16:56:29
问题 Anyone knows if String Aggregation in sqlite is possible? If i have an animal column with 5 rows/datas, how can i combine them so that the output would be in one field 'dog','cat','rat','mice','mouse' as animals Thanks 回答1: You're looking for something like the following: select group_concat(animal) from animals; This will return something like the following: dog,cat,rat,mice,mouse If you don't want to use a comma as the separator, you can add your own separator as a second parameter: select

STRING_AGG not behaving as expected

好久不见. 提交于 2019-12-03 10:44:57
I have the following query: WITH cteCountryLanguageMapping AS ( SELECT * FROM ( VALUES ('Spain', 'English'), ('Spain', 'Spanish'), ('Sweden', 'English'), ('Switzerland', 'English'), ('Switzerland', 'French'), ('Switzerland', 'German'), ('Switzerland', 'Italian') ) x ([Country], [Language]) ) SELECT [Country], CASE COUNT([Language]) WHEN 1 THEN MAX([Language]) WHEN 2 THEN STRING_AGG([Language], ' and ') ELSE STRING_AGG([Language], ', ') END AS [Languages], COUNT([Language]) AS [LanguageCount] FROM cteCountryLanguageMapping GROUP BY [Country] I was expecting the value inside Languages column for

String Aggregation in sqlite

徘徊边缘 提交于 2019-12-03 06:58:15
Anyone knows if String Aggregation in sqlite is possible? If i have an animal column with 5 rows/datas, how can i combine them so that the output would be in one field 'dog','cat','rat','mice','mouse' as animals Thanks You're looking for something like the following: select group_concat(animal) from animals; This will return something like the following: dog,cat,rat,mice,mouse If you don't want to use a comma as the separator, you can add your own separator as a second parameter: select group_concat(animal, '_') from animals; which will return: dog_cat_rat_mice_mouse I think this will be