Assign teacher role to particular users - Moodle - roles

I'm trying to assign a user as a teacher in a course. but i want him to be a teacher only for particular students in the course. lets say i have 10 student enrolled in the course. and i want one of them to be teacher only to 3 students. is it possible?

You can use groups to group users together, so have the teacher and the students in the same group - https://docs.moodle.org/27/en/Groups
Edit the course settings, scroll down to the group settings, change the group mode and save the course.
Then on the course management menu go to users -> groups and create a group for each teacher.

Related

SQL Display results only if the row exists in another table

Is there a way to display results only if that particular value exists, if there are multiple entries of it in another table?
For example, I am trying to display teacher name only if the type is Math. If there are no entries of Math, the column Teacher should display none.
UserName U
Email
Me
row#1.com
Wiz
bow#1.com
Classes C
Username
First
Me
Second
Me
Third
Me
Third
Wiz
Classes
Teacher T
Type
First
A
Math
Second
B
Math
Third
C
NULL
Final result as Math Classes exist for Me
UserName
Email
Teacher
Me
row#1.com
A
Me
row#1.com
B
Final result as Math Classes exist for Wiz with no math classes
UserName
Email
Teacher
Wiz
bow#1.com
None
The issue I'm running into is that my query is displaying either no entries even though user has no math but has other classes, or it's displaying Math and None at the same time.
My current query is as follows:
from User u
join classes c on c.username=u.username
join teachers t on t.classes=c.classes and type ='Math' <---- If I left join, I get 2 entries, if I join, I get 0 entries for non-math folks
where username ='Me'
So the 3 scenarios I want the query to cover:
If user does not exist in the user table (no entry)
If user exists but doesn't have any math (show user None entry)
If user exists and has math (regardless of any other type) display classes - final situation up there
Do I do some kind of select count in the case statement? This query is part of a bigger execution query.
This was SQL Server Management Studio
Would something like this solve your question?
select u.Username,
Email,
CASE WHEN types = 'MATH'
THEN teacher
ELSE 'None'
end as teacher
from users u
join class c on c.username=u.username
join teacher t on t.classes=c.classes
WHERE u.Username = 'Wiz'
db fiddle

SubForm exclusions Microsoft Access

I have a practice database I'm developing in order to become familiar with access. I have created 3 tables, Employees, Computers and Warranty. In the Employee Table there is an Eid (PK), First Name, Last Name and Location. In the computer table there is an Eid(FK), Serial Number (PK) and various identifiers such as brand, size,etc.
Problem
I want the form to show only the employees who currently have a device followed by the devices they have displayed in a subform. *see below
Employee
Rachel Downs
Devices
Dell Latitude
Apple iPad
Instead I get the following result
If I choose sort by employee with a subform, each employee is displayed with the devices they own. Including employees who don't have any devices. I only want to display employees who currently have devices assigned. Any suggestions on how to do this? fyi I used the form wizard to create the forms.
In the parent form invoke the query builder on the recordsource. You'll need to write a query that joins on Employees and Computers and then groups on Employee.
SELECT Employees.Eid
FROM Employees INNER JOIN Computers ON Employees.Eid = Computers.Eid
GROUP BY Employees.Eid
You can add other fields as needed from the Employees table just make sure to group on them as well.

Filtering out records in SQL with a join

I am creating an app that makes guest lists for greek life events at universities.
The two tables I am working with are 'student' table and 'participant' table.
The fields in the student table are: student_id, student_name, university, and chapter.
Students with chapter id's are considered members, and students without chapter id's are considered guests when making guest lists(participant table).
The participant table fields are: participant_id, member(which is related to student_id), guest (which is also related to student_id), and event.
When trying to add guests to the guest list for an event, I wrote the following sql query to filter out students from different universities and that aren't in chapters and weren't already on the list:
$student = getColumn("SELECT guest FROM participant WHERE event = '$event'");
$university = getSqlValue("SELECT university FROM student WHERE student_id = '$member'");
$f->setOption('filter',
"SELECT student_name
FROM `student`
LEFT JOIN participant ON student.student_id = participant.guest
WHERE student.chapter = ''
AND student.university = '$university'
AND participant.guest != '$student'");
So, I know this isn't going to work, because I have a whole array for $student, but even if I try it with one student id, the query doesn't work. It returns empty. If I remove the last AND particpant.guest!= $student, then the query returns all the students at the university that are not members of a chapter.
My question has two parts:
Why wouldn't that query work with one value for student?
Can someone think of a better way to go about doing this?

Create view from tables with generalization relationship

SQL newbie here and I need help with a complex(?) view for my assignment. It's a database which allows teachers to set the grades and number of times a student was absent, for each class the teacher is responsible.
My tables are:
USERS (user_id, name, surname)
STUDENTS(student_id (fk to users.user_id), student_number number)
TEACHERS(teacher_id (fk to users.user_id), title varchar2)
CLASSES(class_id, subject, teacher_id(fk to teacher.teacher_id)
CLASS_REGISTRATION(class_id (fk to classes.class_id), student_id (fk to students.student_id), grade, absent_number)
I am trying to create two views. One where the student can see the class.subject, class.teacher, class_registration.grade, class_registration.absent_number, for every class he has registered.
The other view is for the teachers where they can view, student name, class subject, grade, absent_number, for every class the teacher is responsible.
The generalisation of users -> students, teachers is required and that's what's mostly giving me problems.
EDIT: Here is a query I wrote which seems to give the desired result for the teacher view, I am not sure it the best way though
CREATE OR REPLACE FORCE VIEW "TEACHER_VIEW" ("NAME", "SURNAME", "SUBJECT", "GRADE", "ABSENT") AS
select u.name, u.surname, c.class, r.grade, r.abstent
from users u, class_registration r, students s, class c
where u.user_id = s.student_id
and s.student_id = r.student_id
and c.class_id = r.class_id
/
/
I am not giving you the create view statement but here are some links for you which can help you to learn view and it's related concept.
first
second
And go through these links and as it's your assignment so try to do it by yourself.
And if you face any problems post here.

SQL query number of students per school

I have a table of students and schools. How do I select the total students per school?
I'm sure this is a very simple query, however I'm not sure how to proceed on from this:
SELECT tblSchools.name
FROM tblStudentDetails
INNER JOIN tblSchools
ON tblStudentDetails.schoolId = tblSchools.id
Group by the school and use count() to count the students
SELECT s.name, count(d.id) as students_count
FROM tblSchools s
INNER JOIN tblStudentDetails d ON d.schoolId = s.id
GROUP BY s.name
I want to add on to the accepted answer as well. Working for a school district and continuously having to pull counts of students there are a few additional things to keep in mind. What students are you looking for?
Do you want active students, inactive students, or active and inactive students.
Do you want to include students that have been no showed (were going to come to your school, but ended up not coming for even a day, this is recorded in most student information systems.
Is the student attending multiple schools, in which case you want to exclude them from counting in their second or third school.
I've built the script with the idea of a normalized school district database, where things are broken out by school year, and enrollment.
Often a basic script for me looks a little like this.
SELECT s.SCHOOL_NAME, COUNT(stu.STUDENT_GU) AS STUDENT_COUNT
FROM STUDENT stu
JOIN STUDENT_YEAR sy ON sy.STUDENT_ID = stu.STUDENT_ID
JOIN SCHOOL_YEAR scy ON scy.SCHOOL_YEAR_ID = sy.SCHOOL_YEAR_ID
JOIN SCHOOL s ON s.SCHOOL_ID = scy.SCHOOL_ID
JOIN YEAR y ON y.YEAR_ID = sy.YEAR_ID
WHERE y.SCHOOL_YEAR = 2017
AND (sy.CONCURRENT IS NULL OR sy.CONCURRENT OR != 'Not Concurrent')
AND sy.ENTER_DATE IS NOT NULL
AND sy.STATUS IS NULL
GROUP BY s.SCHOOL_NAME
Because each school year is a new year, students, and schools usually have a table for the basic data that doesn't change. But also tables that are school year specific. In my example STUDENT_YEAR and SCHOOL_YEAR is where we get into the specifics regarding which kids we are actually getting, and where they currently are. I utilize the YEAR table to identify which school year I want to look at.
The STUDENT_YEAR table is where we store the students concurrency flag, enter date, and so within that table I can use in the WHERE clause a way to filter out Inactive Students, Concurrent Students, and ensure each student is counted only once.
If those year values aren't included, at least in my database, I would get all students ever enrolled for every year we've got stored.