Run query where column = * - google-sheets

Need to run a query on google sheets where the column match any(*) value. I'm doing this because the criteria is filled by refering to another cell (like a filter).
Probably I'm missing something in the syntax.
My last try:
=QUERY(PROD!A:U;"SELECT L, SUM(M), SUM(O), SUM(Q), (1-(SUM(Q)/SUM(O)))
WHERE T = '*' AND D = '*' AND U = '*'
GROUP BY L
ORDER BY SUM(M) DESC
LABEL L 'PRODUTO', SUM(M) 'QUANTIDADE', SUM(Q) 'CUSTO', SUM(O) 'VENDA', (1-(SUM(Q)/SUM(O))) 'MARK-UP'")
Thank you in advance.

In Google Visualization API Query Language (not to be confused with T-SQL, MySQL, etc) the clause WHERE T = '*' means that the content of column T is literally the string *.
To test for a cell being nonempty, use T <> '' (for text columns) or T is not null (for numeric columns).
There are also like and matches for more complex text filtering.

Related

Firedac Passing Column name as Parameter

In Delphi Firedac I have a very long query. I would like to reuse it just changing the name of a column via parameter like this
select f1, f2
from t1
where id = :par1
and :colimn_name = :value_name
Passing the :column_name parameter the reult query is like this:
select f1, f2
from t1
where id = 123
and 'department_name' = 'production'
with 2 '' wrapping the column name.
How can I avoid this, is there a specific way in FireDAC?
Thank you.
That's what FireDAC offers macros for: Substitution Variables
select f1, f2
from t1
where id = :par1
and &column_name = :value_name
Setting the actual columns goes this way:
myQuery.MacroByName('column_name').AsRaw := 'department_name';
Edit: As the column name happens to be a DB identifier, using AsIdentifier instead of AsRaw should work as well. That could even be necessary when the column name can be some reserved word in the DB and has to be quoted somehow.

How to select specific column types in SQLite3?

PRAGMA table_info(myTable)
This query selects all the info in a table, for example: if there are 2 columns in a table then this query will select all the column names, column types e.t.c
I just want add one clause i.e I want to get info of specific columns that I define in the query.
Like this:
PRAGMA table_info(myTable) where columnNames = 'a' and columnNames = 'b' // this is wrong query but I just mentioned it to make my question more clear.
How can I do this?
You can pragma_table_info() in a query with a WHERE clause:
SELECT *
FROM pragma_table_info('myTable') -- note the single quotes
WHERE name IN ('a', 'b') -- equivalent: name = 'a' OR name = 'b'
See the demo.

How to FILTER with LARGE condition on similar values?

I have a table shown at FILTER_LARGE.
I would like to FILTER 3 highest values from column F by LARGE condition and 3 corresponding names from column E.
For some reason I would like to avoid using SORT function.
The issue is - how to retrieve the right values when some of cells in F have same numbers?
Maybe Query helps ?
=query(E1:F; "where F is not null order By F desc limit 3")
Alternatively (to include all ties), also try
=ArrayFormula(query(E1:F; "where F >= "&LARGE(unique(F:F); 3)&""))
You might want to add Order By desc to #JPV answer:
=ArrayFormula(query(E1:F, "select E, F where F >= "&LARGE(unique(F:F), 3)&" order by F desc"))

concatenate values from two columns and compare it against one value in sqlite

I am using sqlite in one my ios project where among other columns there are two columns. one has country code for mobile dialing like +880 and other column has rest of the mobile number like 1912353697. Now i want to join values from these two columns and compare the result value against like +8801912353697 and if matches pull the corresponding name value in that table . what would be the right query. I have tried like SELECT name FROM CONTACT_LIST WHERE (SELECT mblDc || mbl FROM CONTACT_LIST) = "+8801617634317" ; but that does not work .
A help would be appreciated.
Try:
SELECT name FROM CONTACT_LIST
WHERE mblDc || mbl = "+8801617634317";
From SQLite documentation: The || operator is "concatenate" - it joins together the two strings of its operands.
please check
How to concatenate strings with padding in sqlite
using substr function we can do the job and the query should be like
SELECT name FROM CONTACT_LIST WHERE (mblDc || mbl) = "+8801617634317" ;

MS Access 07 - wildcard in JOIN query

I've got the following query
SELECT tblUsers.userfullname,
tblReports.reportdate,
tblReports.reportnumber,
tblRawData.reportcategory,
tblRawData.reportissue
FROM tblRawData
RIGHT JOIN (tblUsers RIGHT JOIN tblReports ON tblUsers.userID = tblReports.userID) ON tblReports.reportnumber LIKE "*" & tblRawData.reportnum
WHERE (
((tblUsers.username) Like "*" & [Forms]![frmSelect]![txtUser] & "*")
AND
((tblUsers.userShift) Like "*" & [Forms]![frmSelect]![txtShift] & "*")
);
Which works - except the part of
ON tblReports.reportnumber LIKE "*" & tblRawData.reportnum
what i'm trying to match is instances where
tblReports.reportnumber = 410145
and
tblRawData.reportnum = 12345.410145
or just
tblRawDatw.reportnum = 410145
but for some reason it just will not find that first match (ex: 12345.410145) unless the number is identical like the second match (ex: 410145). I've tried formatting it as a number as well as text - and no luck.
any idea what I may be missing?
Update: I tried making another query with just the two tables and it doesn't like to match. i tried removing the "." (example: 12345.410145 into 12345410145) and no luck. here's my second query.
SELECT tblReports.userID,
tblRawData.reportnum,
tblRawData.reportcategory,
tblRawData.reportissue,
tblReports.reportdate,
tblReports.reportnumber
FROM tblReports
LEFT JOIN tblRawData ON tblReports.reportnumber LIKE "*" & tblRawData.reportnum;
where if the data is like such.
tblReports Report numbers:
410145
410144
410143
410142
410141
and tblRawData report numbers are such:
12345.410145
410143
12344.410141
the resulting query should show me all 5 records from tblReports - but three of those records have the notes and such from tblRawData.
Rewritten to allow for no match.
SELECT
u.userfullname,
r.reportdate,
r.reportnumber,
q.reportcategory,
q.reportissue
FROM (tblusers u
LEFT JOIN tblreports r
ON u.userid = r.userid)
LEFT JOIN (
SELECT
Val(Mid([reportnum],InStr([reportnum],".")+1)) AS RepNo,
r.reportcategory,
r.reportissue
FROM Rawdata AS r) AS q
ON r.reportnumber = q.RepNo
AND q.username Like "*" & [Forms]![frmSelect]![txtUser] & "*"
AND q.userShift Like "*" & [Forms]![frmSelect]![txtShift] & "*"
It is a common enough convention that LEFT JOINs are used rather than RIGHT JOINs.
I didn't check everything, but I have some ideas. Maybe you have to swap the LIKE condition?
tblRawData.reportnum LIKE "*" & tblReports.reportnumber
if that's not the problem, could you try to use the trim function?
Trim(tblReports.reportnumber) LIKE "*" & Trim(tblRawData.reportnum)
The wildcard character for SQL queries is the percent sign '%' not the asterisk. Try using that instead. But if you are including every match then why have that in your query at all?
Access wildcard character reference

Resources