Skip to content

Tag: sql

MySQL : calculate SUM of a Query

i have a mysql query that looks like this : The query returns a table b : I want to do the sum of those values By but it doesn’t work because of a syntax error. is it possible to sum a query like this ? Thanks. Answer Try this:

Improve Query to not have to run multiple times?

I currently have this working query. However, I have to run it multiple times with different parameters to get the total result. I’m wondering if there’s a way I can run a loop or create a column for each query within one query so I can get the complete result without commenting in specific params…

Correct database after backup

I need some help with a query. Actually we have some wrongs DATA in our database. For some technical reason I restore the backup in another schema. So actually in my Schema1.DB1.TBL1 I got the backed up DATA and in my Schema2.DB2.TBL2 I have the same table but with some wrongs DATA. Could you please tell me a…

Re-format table, placing multiple column headers as rows

I have a table of fishing catches, showing number of fish and total kg, for all the fishing days. Current format of the data is showing as below In the other reference table is a list of all the official fish species with codes and names. How can I re-format the first table so the rows are repeated for each

Get Value in Date Range with date parameter

Given 2 tables: Table A Table B I want to produce the following View: My Question, how to get Table A Value inside of that view, based on that transaction date within Table A Date From and Date To? Answer This query will match each table_a entry to every table_b transaction, based only on the transaction date…

Why does my SQL Statement not SUM() up correctly?

I have the following statement: note that = (1 or 4) refers to two statements in the database where 1 is sold and 4 is a refund. With = (1)) I get the following results: Costs – Unitamounts 3.281,10 – 582 With = (4)) I get the following results: Costs – Unitamounts -115,2 – -32 With = …

Using new columns created from PARSENAME

I have split the column PointName using PARSENAME and created 2 new columns and I am needing now to use a WHERE clause to only pull the data for those 6 types. Is there a way to do this? Answer Filling in the blanks a bit, but I would guess you could move the PARSENAME to the FROM and then