How would I find the id of a person in my table who has SYSMIS for all the variables A,B,C & D? A to D are sequential variables.
I can't do a select if because it doesn't accept the to in:
select if (A to D) = SYSMIS.
This will do it:
select if nmiss(A to D)=4.
If the variables weren't sequential you could use
select if nmiss(A, B, C, D)=4.
Related
Currently I have the formula below to grab the dates of attended sessions:
=query('Sessions'!C:P, "Select C, P Where P='Attended'")
Now I need to include another variable to exclude the sessions that are to be rescheduled, so it would be where P=Attended and where Q=Completed or Q=Partial.
I thought
=query('Sessions'!C:Q, "Select C, P Where P='Attended' and (Q='Completed' or Q='Partial')")
would work, but it only chose the ones that were partial. Anyone know what'll fix it?
try:
=QUERY('Sessions'!C:Q,
"select C,P
where P = 'Attended'
and Q matches 'Completed|Partial'")
I'm using a QUERY function in Google Sheets. I have a named data range ("Contributions" in table on another sheet) that consists of many columns, but I'm only concerned with two of them. For simplicity sake, it looks something like this:
I have another table that contains the unique set of names (e.g.: "Fred", "Ginger", etc. each only once) and I want to extract the level # (column B) from the above table to insert the most recent (largest number) in this second table.
Right now, my query looks like this:
=QUERY(Contributions, "select B,C where C='"&A5&"' order by B desc limit 1",1)
The problem is, that it outputs both B & C data - e.g.:
11 Fred
But since I already have the name (in column A of this other table) I only want it to output the value from B - e.g.:
11
Is there a way to output only a subset (in this case 1 of 2) of the columns of output based on a directive within the query itself (as opposed to doing post-processing of the results)?
Outputting a Subset of Columns Used in Query
In order to output only certain columns of a query result, the query only needs to select the columns to be displayed while the constraints / conditions may utilize other columns of data.
For example (as an answer to my own question) - I have a table like this:
I needed to get the data from the row with a name matching another cell (on another sheet) and with the latest (largest) number - but I only want to output the number part.
My initial attempt was:
=QUERY(Contributions, "select B,C where C='"&A5&"' order by B desc limit 1",1)
But that output both B & C where I only wanted B. The answer (thanks to # Calculuswhiz) was to continue using C for the condition but only select on B:
=QUERY(Contributions, "select B where C='"&A5&"' order by B desc limit 1",1)
The following behaviour from Visual FoxPro puzzles me.
CREATE TABLE test_17 (A C(2), B N(10,2))
CREATE TABLE test_18 (A C(2), B N(20))
INSERT INTO test_17 values ('C1', 1037.60)
INSERT INTO test_17 values ('C2', 2411.50)
INSERT INTO test_18 VALUES ('C1', 1037600)
INSERT INTO test_18 VALUES ('C2', 2411500)
The following query
SELECT * FROM test_17 a, test_18 b WHERE a.A = b.A AND a.B*1000 = b.B
only returns the C2 line and not the C1 line whereas:
SELECT * FROM test_17 a, test_18 b WHERE a.A = b.A AND a.B*1000 <> b.B
returns nothing as expected and
SELECT IIF(a.B*1000 = b.B,'T','F') FROM test_17 a, test_18 b WHERE a.A = b.A
returns T, 'T' as expected.
Can someone please explain to me why Visual FoxPro behaves this way? Thank you.
Try
int(a.B*1000) = b.B
In all digital devices, floating point numbers are an approximation, comparisons of them are just a guess.
I'm trying to do an SP in DB2 with 2 select statements. If the first select returns null, perform the second one.
For example
Select a, b, c from table A where...
--If first select returns null
Select a, from table B where...
I tried a lot of ideas but none of them worked.
Thanks
You can use this general pattern, of course you will have to adapt your two result sets to match
WITH first AS
(
SELECT ..result1.. FROM table1
WHERE ..clause1..
)
SELECT ..result1.. FROM first
UNION
SELECT ..result2.. FROM table2
WHERE 0=(SELECT COUNT(1) FROM first)
AND
..clause2..
Here is a simple way to write that
Select a, from table B where...
and not exists (select * from table a where...)
union
select a,.. from table A)
I have similar query:
select
a,
b,
c,
d,
e,
(select somevalue from differenttable where report.a = two.a) as two,
(select somevalue from differenttable2 where report.a = three.a) as three,
(select sum(kol*CAST(price AS BIGINT)) from "otherreport"('01.01.2010', '01.10.2010') as sum
from "report"('01.01.2010', '01.10.2010')
The query works in its original form, but the problem is that in some of the databases(old versions) that i query some of the fields a, b, c, d, e are missing in the result of 'report' stored procedure and i get an error.What would be the best way to handle this ?
I was thinking of select * from reports, but i can not add the subqueries. May be i can not find the right syntaxis to do this.Other way would be to check if the columns exists before
making the select...
There are several things you can do:
Use an aliased SELECT * followed by the subqueries. Instead of doing a simple SELECT * you alias the selectable stored procedure and use myAlias.*:
SELECT
r.*,
(select somevalue from differenttable where report.a = two.a) as two,
...
from "report"('01.01.2010', '01.10.2010') r
Note that this has its own downsides, like moving the "missing columns" problem from the query to the consumer of the query.
Upgrade your databases so that the stored procedure matches your expectations.
Dynamically build the query from the procedure metadata. This is pretty complex, and I currently don't have time to give a full example of this.