I have select query like this
SELECT * FROM ACTITIVY WHERE CODE in ('L','D')
Instead of hardcording the values in IN PARAMETER I have created a PARAM table. The param table has the below values
CODE | CODE_VAL | ACTIVE
TRIGGER_XM | 'L','D' | Y
so when i rewrite the query as below
select * from ops_ACTITIVY WHERE CODE IN (
SELECT CODE_VAL FROM OPS_CONFIG_PARAMETER
WHERE CODE='TRIGGER_XML' AND ACTIVE='Y')
It doesn't work any idea how to resolve this??
You may try like this:
select * from ops_ACTITIVY t1
WHERE t1.CODE IN ( SELECT CODE_VAL FROM OPS_CONFIG_PARAMETER t2
WHERE t2.CODE='TRIGGER_XML' AND t2.ACTIVE='Y' )
As you are checking for the existence of a string inside another string you could try something like this:
select * from activity a where (
select instr(b.code_val, a.code)
from param b
where b.code = 'TRIGGER_XM'
AND active = 'Y'
) > 0;
But it will most likely only work as long as as you have singlechar codes.
Worked for me at: SQL Fiddle
which table are you really using? ACTITIVY or ops_ACTITIVY?
Assuming that those tables are the same, i would suggest that your PARAMETERS Table have the below values:
| CODE | CODE_VAL | ACTIVE |
| ----------- ----------- -------------
| TRIGGER_XM | L | Y |
| TRIGGER_XM | D | Y |
It is much more manageable, and i think makes much more sense to separate the Code Values of L and D in case you only need to select one of them.
Now, the query below would surely fetch both Codes with 'L' and 'D' values from the ops_ACTITIVY table:
select *
from ops_ACTITIVY
WHERE CODE IN (SELECT CODE_VAL
FROM OPS_CONFIG_PARAMETER
WHERE CODE ='TRIGGER_XML'
AND ACTIVE = 'Y');
Related
Consider that my SQLite table has the following schema,
|'''''''''''''''''''''''''''''''''''''
| unique_id(TXT) | object_data(BLOB) |
|'''''''''''''''''''''''''''''''''''''
| | |
| | |
| | |
''''''''''''''''''''''''''''''''''''''
Assume that the row_id property is enabled, and so my question is, for a given unique_id, is it possible to fetch the next 50 records from the table,
using a single SQL query? (Using the row_id property)
Try getting result through this method.
Select * from table_name [WHERE conditions] Limit 50 offset (Select row_id from table_name where unique_id = x);
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
I am stuck with this problem, I'm doing select like this:
select * from mytable;
and getting following results
-------------
|NAME |VALUE|
-------------
|nam1 |val1 |
-------------
|nam2 |val2 |
-------------
|nam3 |val3 |
-------------
Result is always formatted like this, NAME->VALUE.
Also, there are constraints placed on table so only one distinct NAME could appear in result. Also, values could be numbers, varchars, nulls, I don't want to do aggregation on this values.
Now I would like to convert this result to this:
--------------------
|NAM1 |NAM2 | NAM3 |
--------------------
|val1 |val2 | val3 |
--------------------
I tried achieving this result with pivot() function but without much success.
Thank you for your time, best regards :)
EDIT
This is the working example, with hardcoded column values, which is what I want to avoid.
select * from (select name, value from mytable)
pivot (min(value) for name in (
'nam1' as nam1
'nam2' as nam2
'nam3' as nam3
));
Using DECODE Function:
select name,
decode(name,'Name1','value1',0) as Name1,
decode(name,'Name2','value2',0) as Name2,
decode(name,'Name3','value3',0) as Name3,
decode(name,'Name4','value4',0) as Name4
from mytable
group by name
order by name;
I currently have a table in SQLite that looks something like the following, forming a tree-like structure:
+-----+-----------+---------------+
| _id | parent_id | tree_depth |
+=====+===========+===============+
| 1 | 0 | 0 |
| 2 | 1 | (should be 1) |
| 3 | 2 | (should be 2) |
+-----+-----------+---------------+
I have very limited SQLite experience and the table is quite large, so I would hate to have to fill it out manually. Is there a query I could use to update the tree_depth column such that it properly represents the depth of the tree at that node? I tried selecting the parent's tree depth and incrementing, but for some reason it set everything to 1.
Any advise would be greatly appreciated.
EDIT: The query that I'm trying is:
UPDATE table SET tree_depth = (SELECT p.tree_depth FROM table JOIN table p ON p._id=table.parent_id) +1
You need a recursive CTE to compute the tree depth of each entry.
You can then use this data to look up the value to UPDATE:
WITH RECURSIVE depths(id, depth) AS (
SELECT _id, 0
FROM MyTable
WHERE parent_id = 0
UNION ALL
SELECT MyTable._id, depths.depth + 1
FROM MyTable
JOIN depths ON MyTable.parent_id = depths.id
)
UPDATE MyTable
SET tree_depth = (SELECT depth
FROM depths
WHERE depths.id = MyTable._id);
(Note: older Android versions do not support CTEs.)
Please try?
update table
set a.tree_depth = b.parent_id
If it doesn't wok, try to add this too:
FROM table a
INNER JOIN table b
on a._id= b._id
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