return penultimate value [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is it possible to return the penultimate record of a field? I want to do a select that would return me 2 ... Always the second but last record of the field
I use
select top(1) u_lastdado from (select top 2 u_lastdado from cl order by u_lastdado desc ) t order by u_lastdado asc
but doesn't work. He continues to give me the present value and not the old
Example
select u_lastdado from cl where u_lastdado<> ''
u_lastdado
243237000 213968131
update cl set u_lastdado=213968126 where nome ='Eira e Beira, lda'
u_lastdado
243237000 213968126
I need to know how to go get the '213968131' that was formerly
I use SQL SERVER 2012

Is it possible to return the penultimate record of a field?
Not the way you mean it, no. It is not possible.

Related

googl query or SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
I have, for example, ten customers
each customer placed ten orders
I would like to make a query to get the last order for each customer.
I would like to have it as a Google formula
=query
But I don't know the select what I need to enter.
Try below formula-
={UNIQUE(A1:A),
MAP(UNIQUE(A1:A),LAMBDA(x,INDEX(SORT(FILTER(A1:C,A1:A=x),3,0),1,2))),
MAP(UNIQUE(A1:A),LAMBDA(x,INDEX(SORT(FILTER(A1:C,A1:A=x),3,0),1,3)))}
Edit: With QUERY() formula-
=QUERY(A1:C,"select A, max(B), max(C) where A is not null group by A label max(B) '', max(C) ''",0)

How to find Nimi field only with max Vanus? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
SELECT Nimi
FROM Myyjad
WHERE Myyjad.KauplusID
IN (SELECT KauplusID
FROM Kauplused
WHERE Kauplused.Kauplus = [Kauplus?])
AND Myyjad.Vanus > 60
ORDER BY Myyjad.Vanus DESC;
The initial task is: By the name of the store (through the parametric window), display the names of the oldest customers of this store.
I need condition where Myyjad.Vanus is the biggest (I can't use MAX func).
Please check relationships in on the link below.
relationships
sample1
sample2
SELECT TOP 1 Nimi
FROM Myyjad
WHERE Myyjad.KauplusID
IN (SELECT KauplusID
FROM Kauplused
WHERE Kauplused.Kauplus = [Kauplus?])
ORDER BY Myyjad.Vanus DESC;

SQL query: using data in a column as column names in another table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am struggling to get data from within a table that looks like this:
to display horizontally, grouped by GroupID, then the start/process/stop times (in that order) to display on a single row like this:
I have tried writing several SQL case statements but I cant get it to work. I followed some advice online saying to write an IIF expression in a table in SSRS Report Builder but I couldn't get that to work. Any help would be great.
Using plain SQL I think this is the query you're looking for
SELECT
bt.GroupID as 'ID',
bt.EventStartTime as 'StartStartTime',
bt.EventEndTime as 'StartEndTime',
bt.TotalEventDuration as 'StartDuration',
pt.EventStartTime as 'ProcessStartTime',
pt.EventEndTime as 'ProcessEndTime',
pt.TotalEventDuration as 'ProcessDuration',
st.EventStartTime as 'StopStartTime',
st.EventEndTime as 'StopEndTime',
st.TotalEventDuration as 'StopDuration'
FROM
PROCESS_LOG bt
LEFT JOIN PROCESS_LOG pt ON
bt.GroupID = pt.GroupID
LEFT JOIN PROCESS_LOG st ON
bt.GroupID = st.GroupID
WHERE
bt.Event = 'Start'
AND pt.Event = 'Process'
AND st.Event = 'Stop'
I'm assuming that you have to start in order to process and/or stop which doesn't seem unrealistic.
The idea is to join the table 3 times to extract the info for each event, GroupID being the 'glue' to relate them.

Combine where, or and clauses in sql request [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
i want to set a filter for my product list so when the user set the shop name is shows only the products of that selected shop and when he also sets the Price limit it show the products of that same selected shop but with that desired price limit too
my sql request is like this but they told me it's wrong :
select nom from produit where boutique_id=3 or ( boutique_id=3 and Prix<500)
if there is any way i can do what i need to do please tell me
Is this what you want?
select nom
from produit
where boutique_id = 3 and (Prix < ? or ? is null);
The ? is the placeholder for your price parameter.

"Select count (*)" vs count of results from "Select 1" : which is more efficient way to get the rows count in DB2? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two approaches to get count of rows in a table in DB2.
One way is
SELECT COUNT(*) FROM Foo WHERE col1 = val1;
Another way is to count the results (number 1's list) which are retrived from following query with a method in my java code
SELECT 1 FROM Foo WHERE col1 = val1;
Here I will get the "list of number 1's" from second query and then get the size of that list in my java code to get count.
Can somebody explain which is most efficient way to get the rows count ?
select count is faster - because the database only needs to return a single number rather than a potentially long list.