How to select value if only all criteria are met? - ms-access

First time Poster here so I appoligize about the formatting and am really novice at sql, but this has me stumped. That and I am using 2016 MS Access's SQL as well.
I have a table and I want to select only the names of the people who have fulfilled all the requirements.
Table Chore
ID Name Chore Done
1 Joe Sweep Yes
2 Joe Cook Yes
3 Joe Dust Yes
4 Bill Vacuum No
5 Bill Dust Yes
6 Carrie Bathroom Yes
7 John Cook No
8 John Beds No
9 John Laundry Yes
10 Mary Laundry No
11 Mary Sweep No
12 Cindy Car Yes
13 Cindy Garden Yes
In this case, only Joe, Carrie and Cindy's names should be returned because under their name, they finished all their chores.
Help please and thanks in advance!

You can use not in
select name from my_table
where name not in (select name from my_table where chore_done ='No');

You could check the value of max(done), like
select
name
from
my_table
group by name
having max(done) = -1
In Access, Yes/True is -1, No/False is 0, so max(done) is Yes

Related

Moving consecutive results to different columns

I have the following table:
Transaction Id
Authorizer
1
john
1
robert
2
Jane
2
Paul
And the result table I need is like this:
Transaction Id
Authorizer_1
Authorizer_2
1
john
Robert
2
Jane
Paul
How can i make this in Teradata SQL assistant?
Thanks in advance!

MySQL - How to order a Select by a specific value in TOP

I have a DB which is an Attendance List for a Training Program. In this list - First Subscriptions gets Priority - and LOCAL USERS have priority too.
DB:
ID NAME SUBSCRIPTION DATE COUNTRY
1 JOHN 2018-04-05 12:00:00 USA
2 MARY 2018-04-05 12:30:00 CANADA
3 CARL 2018-04-05 13:00:00 USA
I need a way to order the table like this:
ID NAME SUBSCRIPTION DATE COUNTRY
1 JOHN 2018-04-05 12:00:00 USA
3 CARL 2018-04-05 13:00:00 USA
2 MARY 2018-04-05 12:30:00 CANADA
CARL is from USA then I need to give priority to him, even Mary makes his subscription early.
any idea?
** IMPORTANT: Country priority changes according to the location of the training. (here the location is "USA", but can be any country)
I tried this:
SELECT * FROM SUBSCRIPTION_TABLE ORDER BY COUNTRY = 'LOCAL_COUNTRY_VAR', SUBSCRIPTION_DATE
but it did not work.
You appear to want to order first by being in the USA and then by the date:
In MySQL, you can do:
order by (country = 'USA') desc, date
I would recommend creating a separate table with the location and a priority code (integer). Inner join the two and then order by the priority code ascending. USA would have priority 1, CANADA would be 2.

prediction on rowwise data or progressive data

I am working on employee attrition analysis with a table having rowwise data for a (employee like Id, name, Date_Join Date_Relieving Dept Role etc)
eID eName Joining Releiving Dept Married Experience
123 John Doe 10Oct15 12Oct16 HR No 12
234 Jen Doee 01jan16 -NA- HR No 11 (ie she is available)
I can run regression on this data to find the beta coefficient
eID eName Joining Releiving Dept Married Experience
123 John Doe 10Oct15 12Oct16 HR No 12
234 Jen Doee 01jan16 -NA- HR No 11
But I've seen other approach too.. where employee have multiple entries depending on their difference between joining date and current month or relieving month(say Employee A joined in Jan and Left in Dec so he'll have 12 entries updating corresponding columns like experience and marriage etc)
eID eName Dept Married Experience
123 John Doe HR No 0
123 John Doe HR No 1
123 John Doe HR Yes 2
123 John Doe HR Yes 3
can someone tell what differentiate two approaches.. and what is the outcome of this second approach.

Relational Algebra: Natural join with NULL value

Table 1
Customer id city
John 1 LA
Nancy 2 NULL
Table 2
Customer $ in the pocket
John 20
Nancy 30
I am wondering what happen if Table 1 natural join with Table 2? My guess is that the result would be 4 attributes and both John and Nancy will appear.
But my friend told me that only John will appear, Nancy won't because there is a null value.
In the case above, your friend is wrong, you are right!
Let's see a case where it would be otherwise:
Table 'Customer'
Id Name AccNo
1 John 44
2 Nancy NULL
Table 'Account'
AccNo $_in_Pocket
44 20
45 30
Here, with a natural join, we would get all attributes for John but Nancy would be missing from the results.

MySQL update the column with conditions

I am trying to update (middle name - mname) a database table based on a certain condition. SQLfiddle. http://www.sqlfiddle.com/#!9/3c022/2
I would like to know HENRY {null} FORD is belonging to one of other HENRY {A,B} FORD based on the coauthors and update the table.
The author with null middle name is updated with the middle name of the author with the same first and last name and with whom he has more number of common co-authors.
For example, based on the data the results is:
HENRY FORD HENRY FORD ---> this should be updated 'B' due to more common authors
HENRY A FORD HENRY A FORD
HENRY B FORD HENRY B FORD
However,
JACK SMITH JACK SMITH ---> this shouldn't be updated due to no common authors
JACK A SMITH JACK A SMITH
JACK B SMITH JACK B SMITH
Any suggestions are appreciate.