please help me how update fron select in sql [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 8 years ago.
Improve this question
update employees set salary=salary*10/100+salary
where EmployeeID (select EmployeeID from employees where salary<2000)

Try the IN
update employees set salary=salary*10/100+salary
where EmployeeID IN (select EmployeeID from employees where salary<2000)
As suggested by Lamak
update employees set salary=salary*10/100+salary
where salary<2000
Another option.
update employees e1 set salary=salary*10/100+salary
where EXISTS (select NULL
from employees e2
where e2.salary<2000
and e1.EmployeeID = e2.EmployeeID
)
The EXISTS is overkill in your case but may be very usefull.
You should read about it. here's a good start :-) .
In your case you should use only the condition salary<2000 in the WHERE clause.

Related

Updating a column with a Count of data from another column in the same table? [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 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear

mySQL select every record that does not exist in another table [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 2 years ago.
Improve this question
I have 3 tables:
users (id_user)
achievements (id_achievement)
user_achievements (id_user, id_achievement)
I need help selecting every achievement that a user has not yet completed.
Consider a cross join that generates all combinations of users and achievements, and a not exists condition with a correlated subquery to filter out those that were completed already:
select u.id_user, a.id_achievement
from users u
cross join achievements a
where not exists (
select 1
from user_achievements ua
where ua.id_user = u.id_user and ua.id_achievement = a.id_achievement
)

make query in mysql to count member [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 2 years ago.
Improve this question
Write Mysql query with average age counting
Try the following
select
ReportsTo,
count(*) as Members,
avg(age) as Average_Age
from yourTable
where ReportsTo is not null
group by
ReportsTo
This is actually quite easy. This may work for you!
SELECT ReportsTo, COUNT(Members) as Members, AVG(Age) as average
FROM table
GROUP BY ReportsTo
ORDER BY ReportsTo

Write query better - as it is only working for only 1 row in notice date WITH CURDATE? [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 2 years ago.
Improve this question
CREATE TRIGGER NOTICE_ISSUE
AFTER INSERT ON MEMBERS
FOR EACH ROW
INSERT INTO NOTICE (Ssn,LSSN,NOTICE_TYPE) VALUES
((SELECT Ssn from MEMBERS WHERE CURDATE() = NOTICE_DATE),
(SELECT LIB_SSN from MEMBERS WHERE CURDATE() = NOTICE_DATE),'RENEW YOUR MEMBERSHIP');
You are duplicating the select query, it would be better like this:
CREATE TRIGGER NOTICE_ISSUE AFTER INSERT
ON MEMBERS
FOR EACH ROW
INSERT INTO NOTICE (Ssn,LSSN,NOTICE_TYPE)
SELECT Ssn, LIB_SSN, 'RENEW YOUR MEMBERSHIP'
FROM MEMBERS
WHERE CURDATE() = NOTICE_DATE

Duplicate value while using Group By [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 3 years ago.
Improve this question
SELECT location,special,price FROM `tickets`
WHERE event = 'food' GROUP BY location
I think you want, (assuming its mysql) the following:
SELECT location, ANY_VALUE(special) special, ANY_VALUE(price) price
FROM tickets
WHERE event='food'
GROUP BY location ;
ANY_VALUE is strange aggregate function out of normal db standards that returns one of the values arbitarily.
If you wish to not have duplicate results in your rows you can choose only distinct result set.
SELECT DISTINCT location,special,price FROM tickets WHERE event = 'food' GROUP BY location