relational-division

Compound course prerequisites (One or more of a,b,c and either x or y as well as z style)

拥有回忆 提交于 2019-12-22 08:38:06
问题 Thanks everyone for the input, especially during the closing hours of the bounty, it's been incredible helpful. This is a followup question to Select courses that are completely satisfied by a given list of prerequisites, and further explains the situation. It is definitely recommended to read to help understand this question further. (Courses and subjects are distinct entities, subjects are only prerequisites for courses and need not be prerequisites for other subjects - think high school

What are ways to get mutual friends in a (1, 2) (2, 1) friendship scenario?

淺唱寂寞╮ 提交于 2019-12-21 23:09:55
问题 I'm developing a website wherein when a person adds another person as a friend, 2 entries are created. Let's say uid 1 adds uid 2 as a friend, the following rows are created in MySQL. activity_id uid1 uid2 1 1 2 2 2 1 uid 2 becomes friends with uid 3 : activity_id uid1 uid2 1 1 2 2 2 1 3 2 3 4 3 2 What are the ways to get the mutual friends between uid 1 and uid 2 ? I'm using php and MySQL with no PDO experience (for now). [EDIT] Okay, so I decided to organize/normalize the tables. The

What are ways to get mutual friends in a (1, 2) (2, 1) friendship scenario?

こ雲淡風輕ζ 提交于 2019-12-21 22:56:29
问题 I'm developing a website wherein when a person adds another person as a friend, 2 entries are created. Let's say uid 1 adds uid 2 as a friend, the following rows are created in MySQL. activity_id uid1 uid2 1 1 2 2 2 1 uid 2 becomes friends with uid 3 : activity_id uid1 uid2 1 1 2 2 2 1 3 2 3 4 3 2 What are the ways to get the mutual friends between uid 1 and uid 2 ? I'm using php and MySQL with no PDO experience (for now). [EDIT] Okay, so I decided to organize/normalize the tables. The

Find rows that have same value in one column and other values in another column?

社会主义新天地 提交于 2019-12-21 16:59:33
问题 I have a PostgreSQL database that stores users in a users table and conversations they take part in a conversation table. Since each user can take part in multiple conversations and each conversation can involve multiple users, I have a conversation_user linking table to track which users are participating in each conversation: # conversation_user id | conversation_id | user_id ----+------------------+-------- 1 | 1 | 32 2 | 1 | 3 3 | 2 | 32 4 | 2 | 3 5 | 2 | 4 In the above table, user 32 is

Inner queries on a single table with IN and NOT IN conditions

你。 提交于 2019-12-20 04:40:09
问题 This is a modification to my previously answered question I have data in the table like below: ROLE_ID | USER_ID ------------------ 14 | USER A 15 | USER A 11 | USER B 13 | USER D 13 | USER A 15 | USER B 15 | USER D 12 | USER C 15 | USER C I would like to get user ids that ONLY have 13 and 15. So based on the example above, I should only get back USER D The query below was provided in my previous answer and the NOT IN part was added by me, however, that doesn't achieve the goal.. select user

MySQL Relational Division

ぐ巨炮叔叔 提交于 2019-12-20 03:24:22
问题 I am having difficulties to solve one exercise: For which People there is a Restaurant, that serves ALL their favorite beers. (Yes, we actually have this in school :D) I have got 2 Tables that can be used: Table1: Favoritebeer (Name, Surname, beername) Table2: OnStock (beername, restaurant, quantity) My solution would be: OnStock % Favoritebeer There is no such thing like DIVISION in MySQL. Any ideas how I could solve that? I found the following on Wikipedia: http://en.wikipedia.org/wiki

Can you solve this simple SQL query?

别说谁变了你拦得住时间么 提交于 2019-12-19 10:17:23
问题 Suppose it's a website that sells photo cameras. Here are my entities (tables): Camera: A simple camera Feature: A feature like: 6mp, max resolution 1024x768, The thing is between cameras and feature i've got a Many to Many relationship, so i have an extra table: camera -> cameras_features -> feature So, the query is simple: How to get all the cameras that have the feature 1,2 and 3? It's like constructing a bitmap index. Data you can use to test if the solution is ok C1 has features 1,2,3 C2

Select group of rows that match all items in a list

佐手、 提交于 2019-12-17 02:13:11
问题 Assume I have two tables: cars – list of cars carname | modelnumber | ... passedtest – contains every test that a car passed: id | carname | testtype | date | ... 1 | carA | A | 2000 | 2 | carB | C | 2000 | 3 | carC | D | 2001 | 4 | carA | C | 2002 | Now, how can I select a car from the passedtest table that passed all tests (A, B, C, D)? I tried the IN statement but it also matches cars that pass even one test. I am looking for a statement to match all values in a list across all rows. 回答1:

Get records having both values in “IN” using SQL

夙愿已清 提交于 2019-12-14 03:08:05
问题 I need a SQL statement to extract those applicants from the database who have both the attachment tags. The belowq statement works fine if I want aaplicant who have either 7 or 8 as the attachment tag but i need applicant who have both these tags. select distinct(a.id) from applicant a join applicantdeployment ad on a.id = ad.applicantid join ApplicantAttachment at on a.id = at.applicantid where a.applicanttype = 'TCN/LN' and ad.groundlocation in (4,8,14) and ad.deploymentstatus =1 and ad

Selecting suppliers that have at least the same approval codes as the contract requires

浪尽此生 提交于 2019-12-13 21:17:58
问题 Have a table of suppliers that have 'approval codes' (VNDAPP) and a table of contracts that have 'requirement codes' (COXA). Contracts can have any number of requirements and suppliers can have any number of approvals. VNDAPP: (vendor approvals table) VNUM (vendor number) REQMT (approval code) COXA: (contract requirements table) CONTR (contract number) REQMT (requirement) Need to find all suppliers that have approvals that, as a minimum, meet the requirements of a certain contract. Example