You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0

Did you mean to write CREATE TABLE catsub1…, without the $? Is the table name catsub1, or are you trying to insert the value of the $catsub1 variable as the table name? In this case, you need to set the value of $catsub1 properly because apparently it is now 0. $catsub1 = “your_table_name”; $sql = … Read more

SQL query for salary in emp table

You’ll have to get the percentage of the year worked and multiply it by the salary. If the joined_date is before January of that year, use ‘1.00’. Since you did not specify a SQL type, I chose MSSQL as I’m most familiar with it. Here’s an example using MSSQL: DECLARE @yearToFindSalaryFor INT = 2018 DECLARE … Read more

Unable to Subtract Dates SQL Server

Using the sample data you posted (and adapting it slightly), here is my attempt to solve the problem: SELECT BASESCORE, Datediff(dd, MINDATE, MAXDATE) FROM (SELECT BASESCORE, Cast(Max(DATETIME) AS DATETIME) MaxDate, Cast(Min(DATETIME) AS DATETIME) MinDate FROM table1 GROUP BY BASESCORE)T You can take a look at the full working version on SQL Fiddle. Let me know … Read more