I have the following Oracle SQL that works. All that I am trying to do is to add one field to the output and I cant get this SQL working:
Here is my information:
table name: access_log
col name: activity
value: Download file:/webdocs/data/groupXXX/case/03_28_54_9_0000011856.pdf
Now here is my SQL that IS WORKING right now:
select regexp_replace(activity, '^.*/(.*)/.*$', '\1') AS FILENAME,
COUNT (regexp_replace(activity, '^.*/(.*)/.*$', '\1')) AS DOWNLOADS,
FROM access_log where id = 5339 and time_stamp BETWEEN TO_DATE ('2014/02/01', 'yyyy/mm/dd') AND TO_DATE ('2014/02/02', 'yyyy/mm/dd')
GROUP BY regexp_replace(activity, '^.*/(.*)/.*$', '\1')
ORDER BY DOWNLOADS DESC;
But I would like to change the SQL to also display the full values of "activity" all the way to the right but I cant add this field and keep the SQL working.. cna someone please help me..
select regexp_replace(activity, '^.*/(.*)/.*$', '\1') AS FILENAME,
COUNT(1) OVER ( PARTITION BY regexp_replace(activity, '^.*/(.*)/.*$', '\1')) AS DOWNLOADS,
activity
FROM access_log
where id = 5339
and time_stamp BETWEEN TO_DATE ('2014/02/01', 'yyyy/mm/dd') AND TO_DATE ('2014/02/02', 'yyyy/mm/dd')
ORDER BY DOWNLOADS DESC;
We use COUNT() here as a window function approach.
Related
I can get year and month separately in Athena but i don't know how to get YEARMONTH from date.
select year(date1) from table1
select Month(date1) from table1
Please suggest how to get YEARMONTH. Thank you in advance.
You can use date_format to represent your date in needed format:
select date_format(now(), '%Y%m')
I need to update a second table with the results of this query:
SELECT Tag, battery, Wearlevel, SensorTime
FROM (
SELECT m.* , ROW_NUMBER() OVER (PARTITION BY TAG ORDER BY SensorTime DESC) AS rn
FROM [dbo].[TELE] m
) m2
where m2.rn = 1;
But. I had a hard time fixing the SET without messing it up. I want to have a table which has all data from last date of each TAG without duplicates.
Below code maybe you want.
UPDATE
Table_A
SET
Table_A.Primarykey = 'ss'+Table_B.Primarykey,
Table_A.AddTime = 'jason_'+Table_B.AddTime
FROM
Test AS Table_A
INNER JOIN UsersInfo AS Table_B
ON Table_A.id = Table_B.id
WHERE
Table_A.Primarykey = '559713e6-0d85-4fe7-87a4-e9ceb22abdcf'
For more details, you also can refer below posts and blogs.
1. How do I UPDATE from a SELECT in SQL Server?
2. How to UPDATE from SELECT in SQL Server
I have a table japan_dt with below schema:
Prefecture city
北海道 札幌市
Now I want to run the select query on the above table something like:
select prefecture from japan_dt where city = '札幌市'
output should be
北海道
How to achieve this in HIVE ?
I have tried with
select prefecture from japan_dt where city rlike '札幌市'
it's not working
So far what I do is run query builder, click preview, copy content of select, paste in excel, ctrl+H replace " t1." by "" and replace "," by "".
That's not very elegant and takes a few seconds for each table, is there a better way to do that ?
My understanding is that you simply want a 'list' of the columns that are output/referenced in your query (from Query Builder).
If you are actually running the Query Builder step and a new table is created, you can query the DICTIONARY tables for information about that. For example, you could run this in a separate program:
PROC SQL;
SELECT
name AS Column_Name
FROM
DICTIONARY.COLUMNS
WHERE
libname = 'LIBRARY' AND /* Change to the name of the library the table is in. */
memname = 'TABLE'; /* Change to the name of the new table */
QUIT;
So, if you have a query like:
SELECT
Column_A,
Column_B
FROM
LIBRARY.TABLE;
The query I provided atop will give you:
Column_A
Column_B
Which you can simply copy and paste - and not need to replace any characters.
Steps to be performed in UFT API Test:
Get JSON RESPONSE from added REST activity in test flow
Add Open DB connection activity
Add Select Data activity with query string
SELECT Count(*) From Table1 Where COL1 = 'XXXX' and COL2 = ' 1234'
(here COL2 value has length of 7 characters including spaces)
In the above query values in where clause is received(dynamically at run time) from JSON response.
When i try to link the query value using link to data source with custom expression
eg:
SELECT COUNT(*) FROM Table1 Where COL1 =
'{Step.ResponseBody.RESTACTIVITYxx.OBJECT[1].COL1}' and COL2 =
'{Step.ResponseBody.RESTACTIVITYxx.OBJECT[1].COL2}'
then the QUERY changed (excluding spaces in COL2) to:
SELECT Count(*) From Table1 Where COL1 = 'XXXX' and COL2 = '1234'
I eventried with concatenate and Replace string activity but same happens.
Please kindly help..
You can use the StringConcatenation action, to build de Query String.
Use the String as Query in Database "Select data"