HOW CAN I CORRECT THIS SQLITE SYNTAX ERROR [closed] - sql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 24 days ago.
Improve this question
IN MY EMPLOYEE TABLE COLUMN "HIREDATE" HAS (DATETIME) FORMAT AND I AM GETTING ERROR WHEN I TRY RETRIEVE THE DATA BY THIS QUERY BELOW:
SELECT FirstName, HireDate FROM employees
WHERE HireDate ('2002-08-14 00:00:00'')
I AM GETTING AN ERROR IN SQLITE.
Execution finished with errors.
Result: unrecognized token: "'2002-08-14 00:00:00'') "
At line 1:
SELECT FirstName, HireDate FROM employees
--SELECT HireDate FROM employees
WHERE HireDate (

The correct syntax would be:
SELECT FirstName, HireDate FROM employees WHERE HireDate > '2002-08-14 00:00:00'

Related

Write the SQL queries to display the total amount earned by each employee's name and surname [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
So I have two tables and i need to write the SQL queries to display the total amount earned by each employee. tables in picture below
i tried to multiple combinations but it keeps giving me an error. could anyone please show me the way ?
here is the code i tried,
SELECT Employee.FirstName, Employee.LastName, Payments.Value
FROM Payments
LEFT JOIN Employee
ON Employee.EmployeeID = Payements.EmployeeID
ORDER BY Employee.EmployeeID
SELECT Sum(Value) FROM Payments Group By EmployeeID;
You should group and sum the amounts and then than result joined by employeeId with employees to get the specific data, as name, etc.
SELECT
EmployeeId,
FirstName,
LastName,
sm.Total as Total,
FROM
Employees em
JOIN
(SELECT
EmployeeId,
SUM(Value) as Total
FROM
Payments
GROUP BY EmployeeId) sm
ON sm.EmployeeId = em.EmployeeId

Issue with "group by" and "having" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
SELECT *
FROM RF_CustomerCard
WHERE DateOfBirth IN (
SELECT DateOfBirth
FROM RF_CustomerCard
HAVING COUNT(DateOfBirth) > 1
GROUP BY DateOfBirth
)
SQL Server 2019 is saying I have a syntax error by "GROUP"
I am trying to find employees who have the same date of birth
As D. Use a GROUP BY clause with a HAVING clause from Microsofts's SELECT - GROUP BY- Transact-SQL shows HAVING comes after GROUP BY:
SELECT *
FROM RF_CustomerCard
WHERE DateOfBirth IN (
SELECT DateOfBirth
FROM RF_CustomerCard
GROUP BY DateOfBirth
HAVING COUNT(DateOfBirth) > 1
)
ORDER BY DateOfBirth -- Optional

Total salary and commission by RELATIONAL SET OPERATOR [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Employee (emp_no, emp_fname, emp_lname, emp_salary,emp_comm, job_title)
use RELATIONAL SET OPERATOR
-- Write a sql query that calculates the total salary for all employees
-- You need to add the salary and commission
-- Note that some employees don't get a commission (here commission is null)
-- You must need UNION
Please help me to find the answer.
Not sure why you need UNION to do this, Try this one
select sum(ifnull(emp_salary,0)+ifnull(emp_comm,0)) As Total
from yourtable
If you need UNION answer try this
SELECT SUM(salary)
from
(
select sum(emp_salary) As salary
from yourtable
WHERE emp_salary IS NOT NULL
UNION ALL
select sum(emp_comm)
from yourtable
WHERE emp_comm IS NOT NULL
)

I need help to write my query in SQL Server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table employee like :
name salary
jhon 5000
jaz 5000
raja 1234
rubi 1234
I need to get output like
name salary
jhon 5000
raja 1234
NAME should be anyone (jhon and jaz) OR (raja and rubi) for salary 5000,1234 respectively
There's no way to easily express "any" in SQL - you tend to have to give a rule, even if you don't care.
So,
select MIN(Name) as Name,Salary from employee group by salary
Will arbitrarily select the name that sorts earliest alphabetically.
this is one of the other way of getting result
with cte as
(
select *,ROW_NUMBER() over (partition by salary order by name)as rn from table)
select * from cte where rn=2
fiddle demo
You Question is quite incomplete including your criteria but see if this suffice your needs
select name, Salary from [Employee] where Salary = '5000'
will return
jhon 5000 and jaz 5000
select name, Salary from [Employee] where Salary = '1234'
will return
raja 1234 and rubi 1234

I am getting semantic error when i am trying to run this query, not able to see any error [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 9 years ago.
Improve this question
I am getting semantic error when i am trying to run this query, not able to see any error.
Find the ssn of employee with lowest salary
select ssn from employee
where salary < ALL
( select salary from employee);
You trying to find a salary that's lower than all other salaries. That won't work because the minimum salary itself is in the table. When we reach the minimum salary, it gets compared to all other salaries in the table. But the comparison < will fail when we compare the minimum salary to itself.
You need to change < to <=.
SELECT ssn FROM employee
WHERE salary <= ALL (SELECT salary FROM employee);
This will return the ssn's for all employees that have the minimum salary. Equivalently,
SELECT ssn FROM employee
WHERE salary = (SELECT MIN(salary) FROM employee);