How to sum the values of two columns and have it in a new one? [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to sum the values of two columns into a new one, its for analysis purpose (not creating a new column in the database)
I tried using case statement but I have no idea what is happening :
(Basically what I'm trying to say is: if the sum of the 2 columns is equal or grater than one, then count it as 1, if its 0 or null then skip and return zero)
please see the attached pictures

If you are trying to get the the sum of the two columns, you just need ton handle the null values properly.
SELECT COALESCE(speciality_count, 0) + COALESCE(Italian_count, 0)
FROM table_name

Related

joining 2 tables without duplicates [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to join an old sql table with a new one but exclude the duplicate entries, this needs to be in a delphi program as well, and im a noob at that, any ideas?
These both keywords will make your data to combine and display in a single column.
Union - Removes the duplicate entries of the table
Union All - Includes the duplicate entries
It would be better if you provide an example with input and output, that would clarify your question the most.
you can use the union all operator instead of the union operator for joining two tables that not remove duplicates from the table.

How do i find all the students that have got more than 70 in any subjects? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
i have a my sql table having 5 students and each gives 5 exams.
i need to get all the students that have got more than 70 marks in any subject with the name of the subject.
the table looks like this and i am new to mysql so i am not able to find the correct query.
please help !
In your case according to your database model I'd recommend making a query for each subject - 5 in total.
SELECT "enroll_no" FROM "tablename" WHERE "sub1_marks" > 70
and respectively do this for the other columns.
Replace "tablename" with the name of your table.
Each call will return a list of the enroll_no entries for where the number in the column you specified is greater than 70.
This is not very performant and you should change your model to have each exam on a separate row instead for a query like this.

FIx gaps in Mysql counter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I'd like to find the first "gap" in a counter column in an MySQL table. For example, if there are values 1,2,4 and 5 I'd like to find 3, update 4 to 3, 5 to 4 and so on. The problem is that the gap can be in any point of the table (the first value as well) and it can span multiple values.
I know that it's not a good pattern to have and the standard solution would be to ignore the gaps, but in this case it's not really possible to do so.
Can be done in either SQL (using MySQL) or PHP.
Allthough not a really good way to do things, if your only concern is that you want all of your existing rows numbered without gaps, you could go ahead and renumber them in an update like this.
SET #ROW:= 0;
UPDATE TABLE SET COUNTER_ROW = #Row := #Row+1

Concat function returns 0 from one of my columns [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I was trying to insert a concatenate my four columns, however after doing so, one column wasn't being returned right, instead of the respective value of my serial_id, it only gives 0.
Here is the code i was trying to enter and I have provided pictures.
INSERT INTO burseid (tag_id,mm,yyyy,combo)
VALUES ('CV',MONTH(NOW()),YEAR(NOW()),CONCAT(tag_id,'-',serial_id,'-',mm,'-',yyyy);
structure
I'm looking to return the values as CV-01-mm-yyyy, but it keeps returning the serial_id as 0 in any of the rows, unless i manually change it.
Here's the sample data sample data
This shouldn't even run as far as I know, and it looks like you should be doing an INSERT INTO ... SELECT:
INSERT INTO burseid (tag_id, mm, yyyy, combo)
SELECT 'CV', MONTH(NOW()), YEAR(NOW()), CONCAT(tag_id,'-',serial_id,'-',mm,'-',yyyy)
FROM other_table;

can I retrieve Data as array from MySQL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a two table first is simple primary key based table and second table is keyvaluepair for maintaining records.
Now I want to get records from Table in a single object. If they come as comma separate it's good.
Suppose I have table
ID valueID.
When I will run select query I not want a list of rows. I want a single column (in a row) that I can get the information about all valueIds.
Could someone explain me how can I get them in one instead of list?
You probably want to use GROUP_CONCAT.
SELECT GROUP_CONCAT(valueID) FROM table
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
If you need both the ID and the valueID, you're better off sticking with an array.