Sheet contains table and 9 query problem set.
https://docs.google.com/spreadsheets/d/1-YW7prEz2rkCKangks2CeDK2spCidGQa8hJJhXWmGiI/edit?usp=sharing
Trying to solve for each customer request:
1 For Mike, into one cell, list Title and Rating for Title that is specifically "Where is the Sun?" List only those with Rental Date that is not TODAY(), which is 9/1/2022
2 For Lizzy, into one cell with results sorted by latest Rental Date, find all Rental Dates, Ratings, and Elements, specifically by her Favorite Title: Where is the Venus?
3 For Ed, his favorite element is specifically "A", query Rental Date, Source, Title, into one Cell AND/OR bring back Rental Date, Source, Title for rating that is exactly 10.00%
4 For John, find Source, Title, Rating into one cell, sorted by oldest Rental Date, that contain "A" in element but those elements can never contain "K"
5 For Mona, find the Rental Date, Title, and Elements for the lowest rating. In another cell, do the same but find for the highest rating.
6 For Claire, find the Title, Rental Date, and Elements for highest rated title that is "Where is Venus"
7 For Frank, find the Title, Rental Date, and Elements whose Rating is closest to the Average Rating. In another cell, do the same for the the Rating that is farthest from the Average Rating.
8 For Jack, find the Rental Date and Title whose Rating is the biggest outlier in the range of Rating?
9 For Mina, list all Titles that have duplicate Rental Dates, Group titles and state their duplicate duplate Rental Dates.
your A2 cell is 9/1/2002 not 9/1/2022 (TODAY)
1:
=ARRAYFORMULA(TRIM(QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select C,D where C='Where is the Sun?' and A < date '"&TEXT(TODAY(), "e-m-d")&"'", 0)),,9^9)),,9^9)))
2:
=ARRAYFORMULA(TRIM(QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select A,D,E where C='Where is Venus?' order by A desc", 0)),,9^9)),,9^9)))
3:
=ARRAYFORMULA(TRIM(QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select A,B,C where E matches '.*(A,|, ?A$).*' and D = 0.1", 0)),,9^9)),,9^9)))
4:
=ARRAYFORMULA(TRIM(QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select B,C,D where E matches '.*(A,|, ?A$).*' and not E matches '.*(K,|, ?K$).*' order by A desc", 0)),,9^9)),,9^9)))
5:
=ARRAYFORMULA(TRIM({QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select A,C,E where D ="&MIN(D2:D), 0)),,9^9)),,9^9), QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select A,C,E where D ="&MAX(D2:D), 0)),,9^9)),,9^9)}))
6:
=ARRAYFORMULA(TRIM(QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY(A:E, "select C,A,E where C = 'Where is Venus?' order by D desc limit 1", 0)),,9^9)),,9^9)))
7:
=ARRAYFORMULA(TRIM({QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY({A2:E, ABS(D2:D-AVERAGE(D2:D))&""}, "select Col3,Col1,Col5 where Col6 ='"&MIN(ABS(D2:D-AVERAGE(D2:D)))&"'", 0)),,9^9)),,9^9), QUERY(CHAR(10)&FLATTEN(QUERY(TRANSPOSE(QUERY({A2:E, ABS(D2:D-AVERAGE(D2:D))&""}, "select Col3,Col1,Col5 where Col6 ='"&MAX(ABS(D2:D-AVERAGE(D2:D)))&"'", 0)),,9^9)),,9^9)}))
8:
no idea what "biggest outlier in the range of Rating" is. if you want that negative value just say so...
9:
kindly provide an example of the desired result in your sample sheet
I have 2 sqlite3 tables :
FND is a Table of names and their likely gender i.e.:
nm,gndr <-column names
Aliyah,F
Moses,M
Peter,M
Members is second table i.e.
Fname,Lname <-column names
DAVID X, BAKER
MARY MIA,MCGEE
TINA HEATHER,JOHNSON
JIM PETER TOM, SANTINO
The members table has first and middle names in the fname column.
I am trying to write a query to list the Members table fnames column, with a generated column indicating gender based on the first word in the fname column.
I tried this but it didn't work:
select m.fname,(select gndr from FND where upper(nm) like m.fname||'%')as gender
from Members m
can anyone correct my sql statement?
... upper(nm) like m.fname||'%'
Let's look at some example values:
nm: 'David'
fname: 'DAVID X'
SQL: 'DAVID' LIKE 'DAVID X%'
This obviously does not match.
You have to reverse the LIKE operands:
m.fname LIKE nm||'%'
I have Google spreadsheet with a list of names in a column. (EX: David, Daniel, John, Cooper).
I made a drop down list of those names. Lets say I two more columns with Age and Birthday.
I want to show the age and birthday column information pertaining to 'David' when I choose 'David' from the drop down list.
A drop down list acting as a 'in spreadsheet filter'.
Any way to do this?
Ive tried the =FILTER() and =UNIQUE() but they don't quite get me what I want. Thanks for the help
Assuming you have the drop down list in cell A1 (of sheet 2) and the columns with data are in sheet1
col A names
col B age
col C birthday
in cell B1 (of sheet2)
=QUERY(Sheet1!A1:C, "Select B, C where A = """&A1&""" ", 1)
I have been asked this question;
You list county names and the surnames of the representatives if the representatives in the counties have the same surname.
and I have the following tables;
***REPRESENTATIVE***
REPI SURNAME FIRSTNAME COUNTY CONS
---- ---------- ---------- ---------- ----
R100 Gorege Larry kent CON1
R101 shneebly john kent CON2
R102 shneebly steve kent CON3
I cant seem to figure out the correct way to ask Orical to display a surname that exists more then twice and the surnames are in the same country.
I know how to ask WHERE something = something, but that's doesn't ask what I want to know.
It sounds like you want to use the HAVING clause after doing a GROUP BY
SELECT surname, county, count(*)
FROM you_table
GROUP BY surname, county
HAVING count(*) > 1;
If you really mean "more than twice" as you wrote, none of the data you'd want HAVING count(*) > 2 but then none of your sample data would be returned.
In words, this SQL statement says
Group the data into buckets by surname and county. Each distinct combination of surname and county is a separate bucket.
Count the number of rows in each bucket
Return those buckets where there are at least two rows
Let's say I have table data similar to the following:
123456 John Doe 1 Green 2001
234567 Jane Doe 1 Yellow 2001
234567 Jane Doe 2 Red 2001
345678 Jim Doe 1 Red 2001
What I am attempting to do is only isolate the records for Jane Doe based upon the fact that she has more than one row in this table. (More that one sequence number)
I cannot isolate based upon ID, names, colors, years, etc...
The number 1 in the sequence tells me that is the first record and I need to be able to display that record, as well as the number 2 record -- The change record.
If the table is called users, and the fields called ID, fname, lname, seq_no, color, date. How would I write the code to select only records that have more than one row in this table? For Example:
I want the query to display this only based upon the existence of the multiple rows:
234567 Jane Doe 1 Yellow 2001
234567 Jane Doe 2 Red 2001
In PL/SQL
First, to find the IDs for records with multiple rows you would use:
SELECT ID FROM table GROUP BY ID HAVING COUNT(*) > 1
So you could get all the records for all those people with
SELECT * FROM table WHERE ID IN (SELECT ID FROM table GROUP BY ID HAVING COUNT(*) > 1)
If you know that the second sequence ID will always be "2" and that the "2" record will never be deleted, you might find something like:
SELECT * FROM table WHERE ID IN (SELECT ID FROM table WHERE SequenceID = 2)
to be faster, but you better be sure the requirements are guaranteed to be met in your database (and you would want a compound index on (SequenceID, ID)).
Try something like the following. It's a single tablescan, as opposed to 2 like the others.
SELECT * FROM (
SELECT t1.*, COUNT(name) OVER (PARTITION BY name) mycount FROM TABLE t1
)
WHERE mycount >1;
INNER JOIN
JOIN:
SELECT u1.ID, u1.fname, u1.lname, u1.seq_no, u1.color, u1.date
FROM users u1 JOIN users u2 ON (u1.ID = u2.ID and u2.seq_no = 2)
WHERE:
SELECT u1.ID, u1.fname, u1.lname, u1.seq_no, u1.color, u1.date
FROM users u1, thetable u2
WHERE
u1.ID = u2.ID AND
u2.seq_no = 2
Check out the HAVING clause for a summary query. You can specify stuff like
HAVING COUNT(*) >= 2
and so forth.