I have a problem with sqlite3 in this string
select group_concat(persons.name, ', ') as Актеры
from films_persons join persons on persons.id = films_persons.person_id
where films_persons.film_id = 1 and role = Актеры
films_persons looks like this:
film_id | person_id | role
1 | 1 | "Actors" (or "Актеры" in my case)
persons:
id | name | birth_date
1 | Leonardo | 11.11.1974
I need to group all persons.name in 1 string, and this call must return "Leonardo".
Full name of error is "sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) misuse of aggregate: group_concat()".
In mysql, you need to do:
group_concat(persons.name separator ', ')
instead of:
group_concat(persons.name, ', ')
https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=20172b9b99dfcf7dcdf7ccf00efd49f4
But it appears from your error that you are using sqlite, not mysql, in which case your syntax is correct: https://dbfiddle.uk/?rdbms=sqlite_3.27&fiddle=691caef008dbade5c1dde83e4e495c7f
Related
I m getting database name from let statement (dbname) , the issue im getting blank output ,but when I pass the db name [when I give as hardcoded value, the query is working] . please help me to understand what the issue in query.
let view=datatable(Property:string,Value:dynamic)[];
let viewFile=datatable(FileName:string)[];
let dbnameview=datatable(dbname:string)[];
alias database db = cluster(X).database('');
let dbname=tostring(toscalar((
union isfuzzy=true dbnameview, cluster(X).database('$systemdb').Operations
| where Operation == "DatabaseCreate" and Database contains "oci-"| where State =='Completed'
and StartedOn between (datetime(2020-04-09) .. 1d)
| distinct Database , StartedOn
| order by StartedOn desc
| take 1 )));
//let dbname= 'Y';
let latestInfoFile = toscalar((
union isfuzzy=true viewFile,cluster(X).database(dbname).['TextFileLogs']
| where FileName contains "AzureStackStampInformation"
| distinct FileName
| order by FileName
| take 1)) ;
union isfuzzy=true view,(
cluster(X).database(dbname).['TextFileLogs']
| where FileName == latestInfoFile
| distinct LineNumber,FileLineContent
| order by LineNumber asc
| summarize StampInfo=(toobject(strcat_array(makelist(FileLineContent,100000), "\r\n")))
| mvexpand bagexpansion=array StampInfo
| project Property=tostring(StampInfo[0]), Value=StampInfo[1]
)|where Property contains "StampVersion" | project BuildNumber = Value;
what you're attempting to do isn't supported, as mentioned in the docs: https://learn.microsoft.com/en-us/azure/kusto/query/databasefunction
Please help in extracting a data of number of executions against respective id
For e.g. I have temp1 table with data of id and DT where id is given in the form below :
SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439
SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439
SNGL~27321~SUBM~29329_17227~20170815.CSV.20170815113439
I need the result as below :
id number of exec
28867 2
29329 1
The query is below:
select count(A.DT)
from temp1 a
where A.id like '%28867%'
and A.DT >= to_date( '01-Aug-2017','dd-MON-yyyy')
and A.DT < to_date('01-Sep-2017','dd-MON-yyyy')
The problem i am facing is to extract ids from the column of id using like operator.
Please help me to retrieve the result in TOAD FOR ORACLE
You can use REGEXP_REPLACE function, or a combination of SUBSTR and INSTR functions to extract this number from the string.
The latter is faster than the pattern matching in REGEXP_REPLACE, so if there is a huge table of strings I would use the second option.
Assumming that SUBM~ substring is always before the number, this should work:
With my_data as (
select 'SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439' as str from dual union all
select 'SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439' from dual union all
select 'SNGL~27321~SUBM~29329_17227~20170815.CSV.20170815113439' from dual
)
SELECT
regexp_replace( str, '.*SUBM~(\d+).*', '\1' ) as x,
substr( str,
instr( str, 'SUBM~' ) + length('SUBM~'),
instr( str, '_', instr( str, 'SUBM~' ) )
- instr( str, 'SUBM~' )
- length('SUBM~')
) as y
FROM My_data;
| X | Y |
|-------|-------|
| 28867 | 28867 |
| 28867 | 28867 |
| 29329 | 29329 |
i have the following table friend
id | first_name | last_name | gender | age | mobile
1 | bobby | roe | male | 21 | 541-5780
how to concatenate multiple column (first_name & last_name) values into a single column to get the following result?
full_name
bobby roe
i have writen the following query but it does not work
declare #full_name varchar(max)
select #full_name = COALESCE(#full_name + ', ', '') + first_name, last_name
from friend
select #full_name
More than one way to achieve this:
SELECT CONCAT(first_name, ' ' ,last_name) AS full_name;
For earlier versions (Where CONCAT is not a built in function):
SELECT first_name + ISNULL(' ' + last_name, '') as Full_Name from [YourTable]
This as well should give you the same result
SELECT COALESCE(first_name, '') + COALESCE(last_name, '') as FullName FROM [YourTable]
I have a table with this structure:
id | IDs | Name | Type
1 | 10 | A | 1
2 | 11 | B | 1
3 | 12 | C | 2
4 | 13 | D | 3
except id nothing else is a FOREIGN or PRIMARY KEY. I want to select a row based on it's column values that are not PRIMARY KEY. I have tried the following syntax but it yields no results.
SELECT * FROM MyTable WHERE Name = 'A', Type = 1;
what am I doing wrong? What is exactly returned by a SELECT statement? I'm totally new to Data Base and I'm currently experimenting and trying to learn it. so far my search has not yield any results regarding this case.
Use and to add multiple conditions to your query
SELECT *
FROM MyTable
WHERE Name = 'A'
AND Type = 1;
I have the following query which works:
SELECT
SoftwareList,
Count (SoftwareList) as Count
FROM [assigned]
GROUP BY SoftwareList
This returns the following result set:
*SoftwareList* | *Count*
--------------------------
Office XP | 3
Adobe Reader | 3
Dreamewaver | 2
I can also run the following query:
SELECT
GROUP_CONCAT(LastSeen) as LastSeen
FROM [assigned]
WHERE SoftwareList = 'Dreamweaver';
Which would return the following result set:
*LastSeen*
----------
2007-9-23,2012-3-12
I wish to combine both of these queries into one, so that the following results are returned:
*SoftwareList* | *Count* | *LastSeen*
--------------------------------------------------------
Office XP | 3 | 2001-2-12,2008-3-19,2002-2-17
Adobe Reader | 3 | 2008-2-12,2009-3-20,2007-3-16
Dreamewaver | 2 | 2007-9-23,2012-3-12
I am trying this but don't know how to refer to the initial SoftwareList variable within the nested statement:
SELECT
SoftwareList,
Count (SoftwareList) as Count,
(SELECT
GROUP_CONCAT(LastSeen) FROM [assigned]
WHERE SoftwareList = SoftwareList
) as LastSeen
FROM [assigned]
GROUP BY SoftwareList;
How can I pass SoftwareList which is returned for each row, into the nested statement?
I think this is what you want:
SELECT SoftwareList, COUNT(SoftwareList) AS Count, GROUP_CONCAT(LastSeen)
FROM assigned GROUP BY SoftwareList