may someone give some advice on this? There is 2 repeated fields. I can't run the query.
My query is:
SELECT
t
FROM claritas-bigdata-poc.Sushi_King.member_with_transaction,
UNNEST(transactions.transaction) AS t
enter image description here
enter image description here
You can use below approach
select t.*
from `claritas-bigdata-poc.Sushi_King.member_with_transaction` t1,
t1.transactions t2, t2.transaction t
Try this (official docs):
SELECT t
FROM claritas-bigdata-poc.Sushi_King.member_with_transaction, UNNEST(transactions), UNNEST(transaction) AS t
or
SELECT transaction
FROM claritas-bigdata-poc.Sushi_King.member_with_transaction, UNNEST(transactions)
SELECT transaction.*
from `claritas-bigdata-poc.Sushi_King.member_with_transaction`
,UNNEST(transactions) transactions
,UNNEST(transactions.transaction) transaction
Related
I have a table that consists of potentially multiple sequences to each schedules. I would like to output a single (latest) record from each sequence. Below is an example of the table, and the output I'm looking for:
Table sample:
Expected output:
The table name is dataschedule - could you let me know how to best write the sql query to get this data? Thank you!
Hmmm . . . if you want the latest sequence, you can use a correlated subquery:
select t.*
from t
where t.sequence = (select max(t2.sequence)
from t t2
where t2.schedule = t.schedule and t2.id = t.id
);
In most databases, this has quite good performance with an index on (id, schedule, sequence).
Please try this, i havent tested it as you dint provide the insert and create table scripts. Just replace table_name by you table name.
select table_name.*
from table_name, (select ID,schedule,max(sequence) from table_name group by ID,schedule) a
where
table_name.ID = a.ID and
table_name.schedule = a.schedule ;
I have written a query like this :
select *
from DATASYNCH_HA_TO_TRG_AUDIT_HIST
where PSX_BATCH_ID IN (select PSX_BATCH_ID
from DATASYNCH_HA_TO_TRG_AUDIT_T
);
Here,when I execute the sub-query alone, it results some values and when I put those values in the place of sub-query the main query also returns some values.But,when I use this whole query ,it does not result any values.How is it possible?
Hope PSX_BATCH_ID column datatype is integer. if it is varchar filed, then trim the value.
SELECT *
FROM DATASYNCH_HA_TO_TRG_AUDIT_HIST
WHERE TRIM(PSX_BATCH_ID) IN
(SELECT TRIM(PSX_BATCH_ID) FROM DATASYNCH_HA_TO_TRG_AUDIT_T);
Instead of using IN query, use JOIN
SELECT *
FROM DATASYNCH_HA_TO_TRG_AUDIT_HIST A
INNER JOIN DATASYNCH_HA_TO_TRG_AUDIT_T B
ON (A.PSX_BATCH_ID = B.PSX_BATCH_ID)
Really Sorry guys,I found out it was actually a database issue.I ran the query recently in a procedure,it is working fine.
how it is possible to add where to query , to do converting or replacing or max value!
max(convert(int,replace(( QueueNum ),'-',''))) from [Queue]
i want to return max of records that have something special , in where clauses for QueueNum .
Edited :
Data :
1981-1-1232
1981-1-1235
1981-1-1234
1981-2-1
1981-2-2
1981-2-13
how it is possible to return max value of just record started with 1981-2
I guess it is MSSql database in this case try to use the following statement without any conversion:
SQLfiddle demo
select TOP 1
QueueNum
from Queue where QueueNum like '1981-2-%'
order by LEN(QueueNum) desc, QueueNum desc
Not sure if I am giving a good answer, but you can write your query as
Select max(MyValue) from (Select Convert(int, replace((QueueNum),'-','')) as MyValue from [Queue]) MyTable
What it does is that it create a Temporary table in memory which is of one column MyValue and of type Int, this then find Max from that table. I notice that sometime "MyTable" [table alias] is important in such query to perform especially on SQl Server.
Put your condition in having clause
Is this what you want?
SELECT MAX(CONVERT(INT, REPLACE((QueueNum),'-','')))
FROM Queue
WHERE QueueNum LIKE '1981-2%'
SQLFiddle.
select sec_sec_nm,count(1)OVER() from nms_num_scheme
where nms_sec_nm like 'CMIG4%';
This query runs in one Oracle DB.
But the same query does not return any data in other DB though data are available.
This should work:
SELECT sec_sec_nm from nms_num_scheme where nms_sec_nm like 'CMIG4%';
I really don't know what you're trying to do with:
select sec_sec_nm,count(1)OVER()
But I don't think that will work at all.
select sec_sec_nm,count(1) cnt from nms_num_scheme
where nms_sec_nm like 'CMIG4%'
group by sec_sec_nm
mysql
create temporary table t2
select min(id)
from mycontent
group by download_link;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Your mycontent table may be locked by some other transaction when you trying to select from it.
Maybe try doing them separately.
1) create temporary table t2;
2) select min(id) from mycontent group by download_link;
It's worth a shot.
As I understand group_by, you need to select the grouped fields for the query to make sense. What is it that you try to accomplish?
Imagine this table:
download_link, id
-----------------
'' , 3
'foo' , 3
This, using your query, would select
3
3
and therefor explain your locking problem because row 1 is locked by the transaction already but needs to be replaced by row 2.