I want to count the student name field.
i have three table
table 1
invoice
invoice_id student course_id timing_id day_id
table 2
course
course_id course_name
table 3
timing
timing_id time
table 4
days
days_id name
I want to count the number of students that are in one course, in same timing, in same day from invoice table
what is the query?
view , model, controller?
Try to learn Group by and Having in mysql then you can solve this problem
Related
I have 2 tables
From table 1(student): I want id, name, and roll_no
From table 2(score): I want SUM(total), SUM(score) with some condition
And I want all student same class data from student table combine with score table to get each student SUM(total) and SUM(score) of some condition in student table.
In score table I have student_id name column and in student
I have id column which can be linked to each other if possible...
How can I achieve this??
I want this all-in-1 query to get the data in ascending order by score column...
I have two mysql tables:
table 1: product
productId productName
1 One
2 Two
table 2: branch
branchId branchName
1 Branch One
2 Branch Two
3 Branch Three
these two tables need to be merged into a third table
table 3: productopening
openId productId branchId
The id is an auto increment id. the first two tables have data that are not related. I mean, row for id=1 in table 1 has nothing to do with the row for id=1 in table two. So, I basically want to write a mysql script which would insert values into table 3 to look like this in the end:
table 3: productopening
openId productId branchId
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
6 2 3
the ids in the old tables and the new table don't have to match. Just the data from the tables need to be in the new table. I am very new to mysql and if anyone can help me with this, it would be great!
That's It.
I hope this query will work:
INSERT INTO productopening(SELECT null, product.productId, branch.branchId FROM
product CROSS JOIN branch ORDER BY product.productId);
You can use cross join and insert select
insert into productopening
select product.id, branch.id
from product
crossjoin branch
if you need an ordered result (order in insert have no sense) you must explict an order by clause in select
select id, productId , branchId
from productopening
order by productId , branchId
or if you need that the creation of the productopening id is ordered then you can use and ordered select
insert into productopening
select product.id, branch.id
from product
crossjoin branch
order by product.id, branch.id
Edited--
Table1 name is ownership_profile
Table2 name is socity_unit
Colum in Table1: NAME and UNIT_ID
Colum in Table2: wings and unit_no
How to join in one table
if there are N rows in table socity_unit with the same socity_id (as sid in table ownership_profile) then you will see the cartesian product of socity_unit X ownership_profile.
Thus, for every row in ownership_profile you will get each matching row in socity_unit.
Now, because you have a '*' in the select statement you will get all columns from both tables. If the first table has many-many columns then there is an illusion that the rows are duplicated, till you scroll to the right, in order to see the columns from second table ...
Is this your case?
I am working on a school database system based on php mysql. the basic structure is as below:
Table Class-Details of all classes.
Table Student-Details of all students
Table Semester-Details of all Semesters
Table class–Semester. This table solves many to many relation, primary key- IDs of both class and semester.
Table Subject -Details of all Subjects
Table class–Subject. This table solves many to many relation, primary key- IDs of both class and semester.
Table marks- consists of student ID, Subject ID, Semester ID, Marks Achieved.Foreign Key ClassID, SemesterID, SubjectID
I am trying to get a table in below mentioned format:
ENGINE = InnoDB
AUTO_INCREMENT = 53
DEFAULT CHARACTER SET = utf8;
So far I could achieve individual marks of subjects in every record
my query:
SELECT
m.MarkID, m.studentID,
sm.ExamName, sb.Subject,
sm.MaxMarks, m.MarksRecvd
FROM marks AS m
RIGHT JOIN student AS st
ON m.studentID=st.studentID
RIGHT JOIN semester AS sm
ON m.ExamID=sm.ExamID
RIGHT JOIN subject AS sb
ON m.SubjectID=sb.SubjectID
WHERE m.studentID = $studentID
Please help me on this... I am getting a record for every mark recvd like below.
However I want to group all semester marks in one row like below:
Friends pls let me know if my query is clear
I am trying to pull all of the records in each of these tables that have a value in Games.date_added that is greater than an inputed date. Trying to pull all the new records.
Can I do that all in one query? Or is it easier to just add a date_added field to each table and query each table separately?
GAMES
id
date_added
game_name
release_date
game_category
game_type
game_console
TROPHIES
trophies_id
game_name
tr_name
tr_description
tr_color
tr_ach_value
TROPHY_TOTALS
trophy_totals_id
game_name
bronze_ttl
silver_ttl
gold_ttl
plat_ttl
hidden_ttl
It will be much better and clearer if you do 3 separate queries. Each one will give you a different amount of rows. The query given by glglgl that uses 2 joins will result in multiplied rows from the games table. This is because tropies and tropy totals can contain multiple records with same game. Of course if game_name is a unique column than the join will be OK.
First of all, it would surely better to have your foreign key fields in TROPHIES and TROPHY_TOTALS be id resp. game_id rather than game_name.
This said, I will concentrate on your current table structure.
SELECT <wanted fields>
FROM GAMES
LEFT JOIN TROPHIES USING (game_name)
LEFT JOIN TROPHY_TOTALS USING (game_name)
WHERE date_added > <given>