Name Class ID Joining date First payment
1 ABCD 710091 17/08/2019 500
2 ABCD 7100091 17/08/2019 500
3 DEFG 710092 18/08/2019 600
4 DEFG 710092 18/08/2019 6000
In the above example 2 can be a duplicate entry of 1 (class id is the only item different)
and 4 can be a duplicate entry of 3
i need to group rows with more than 2 column are same
expected output
group 1
1 ABCD 710091 17/08/2019 500
2 ABCD 7100091 17/08/2019 50
group 2
3 DEFG 710092 18/08/2019 600
4 DEFG 710092 18/08/2019 6000
I have a result table like this
UniqueID
Value
1
100
1
98
1
99
2
100
2
98
3
99
and I want to display the result as follows using SQL
UnqiueID
Value1
Value2
Value3
1
100
98
99
2
100
98
3
99
Please suggest queries using single table and multiple tables
I have two tables 'Sample' and 'Results', I want to pull the id's of Sample table and map it into the Results table.
I will put in an example for better understanding,
sample_id (Auto increment) Sample_No Sample_Name Experiment_id
1 NL-1 ABC 300
2 NL-2 XYZ 300
3 NL-3 JKL 300
4 NL-3 WER 301
Now Sample No : NL-1 will have multiple result name and so will the other Sample_Names
result_id (Auto increment) Sample_No Result_Name Experiment_id
1 NL-1 abc 300
2 NL-2 abc 300
3 NL-3 abc 300
4 NL-1 xyz 300
5 NL-2 xyz 300
6 NL-3 xyz 300
7 NL-1 jfk 300
8 NL-2 jfk 300
9 NL-1 abc 301
10 NL-1 xyz 301
So what I want to do is pull the sample id by comparing it to the Experiment_id and the Result_Name. Something like this.
result_id (Auto increment) **Sample_id** Sample_No Result_Name Experiment_id
1 1 NL-1 abc 300
2 1 NL-2 abc 300
3 1 NL-3 abc 300
4 2 NL-1 xyz 300
5 2 NL-2 xyz 300
6 2 NL-3 xyz 300
7 3 NL-1 jfk 300
8 3 NL-2 jfk 300
9 4 NL-1 abc 301
10 4 NL-1 xyz 301
I know how to create a trigger to pull the recent Experiment_id but I have been unable to do this particular task. Please, help me.
create trigger SAMPLE_before_insert before insert on SAMPLE FOR EACH ROW
set new.Experiment_id = (select max(Experiment_id) from EXPERIMENT);
Thanks.
Hi I have two tables Experiment and Sample.
I want to create a trigger such that if there is a entry in the 'Sample' table it should check if 'Experiment_name' and 'Sample_name' is same as the previous entry and if both matches then it should update that row and if not then it should enter a new row.
For example
EXPERIMENT TABLE
Experiment_id(auto_incremented) Exp_name
1 ABC
SAMPLE TABLE
Sample_id Experiment_id Experiment_name sample_name Sample_result
1 1 ABC abc 100
2 1 ABC xyz 100
3 1 ABC hjk 300
**New Entry - Experiment name - ABC and sample_name - xyz then Sample_result - 200 **
SAMPLE TABLE
Sample_id Experiment_id Experiment_name sample_name Sample_result
1 1 ABC abc 100
**2 1 ABC xyz 200**
3 1 ABC hjk 300
If Experiment name - ABC and sample_name - wer did not exist then Sample_result - 200 should be inserted as a new row.
SAMPLE TABLE
Sample_id Experiment_id Experiment_name sample_name Sample_result
1 1 ABC abc 100
2 1 ABC xyz 100
3 1 ABC hjk 300
**4 1 ABC wer 200**
I could simply do this using update but I am using MySQL workbench and I will be impoting data from CSV using the import wizard and that is why I want it to be automated.
I am using mysql 5.7.22. Please someone help me, thanks!!
I have table with the following data
id | name | passed | rank | Class
1 abc y 1 1
2 xyz y 1 2
3 lmn n 54 1
4 opq n 54 2
5 rst y 2 1
6 uvw y 2 2
What sql query can give me the following result:
id | name | passed | rank | Class
1 abc y 1 1
2 rst y 2 1
4 def y 55 1
3 lmn n 54 1
5 xyz y 1 2
6 uvw y 2 2
7 opq n 54 2
Group by class first all students with class = 1 , then 2 and so on.
the passsed == n should always come by the end and if there are 2 students with passed == n they should be ordered rank wise.
rest of the students with passed == y should be orders rank wise.
Tried:
select id, name, passed, rank, class
from students
ORDER BY passed DESC, rank
This gives :
id | name | passed | rank | Class
1 abc y 1 1
4 xyz y 1 2
2 rst y 2 1
5 uvw y 2 2
3 def y 55 1
6 opq n 54 2
3 lmn n 54 1
So I get passed==n at bottom and rest ordered as per rank.I think the only thing remaining is group by class.
Can't you just add the order or class first?
select id,
name,
passed,
rank,
class
from students
ORDER BY `Class`,
passed DESC,
rank