sql-update

SQL to update the salary of employees with their department's average salary

醉酒当歌 提交于 2020-01-07 09:34:34
问题 Consider the table employee : desc employee; Name Null? Type -------------------------- -------- ------------ EMPLOYEENO NOT NULL NUMBER(4) ENAME VARCHAR2(15) JOB VARCHAR2(15) MGR NUMBER(4) HIREDATE DATE SAL NUMBER COMM NUMBER DEPTNO NUMBER(2) Contains with values of deptno , sal as: DEPTNO SAL ---------- ---------- 10 2450 10 5000 10 1300 20 2975 20 3000 20 1100 20 800 20 3000 30 1250 30 1500 30 1600 30 950 30 2850 30 1250 Need to update the salary of employees with their department's

Nested Cursor based update

烈酒焚心 提交于 2020-01-07 06:36:47
问题 So this is for a SSRS report so I'm using temp tables. I have two tables, one for transactions that I'm just using it to pull the account and the amounts. The second is amortized delinquency information I'm trying to adjust based on the transaction but I'm running into syntax issues. Are case statements not allowed to be used with cursors or updates? --Example Transaction:Account 123456 Principal 500.00 Interest 250.00 delinquent 5 months of 200 principal each month, the transaction had

How to perform UPDATE operation on two tables having two similar fields and one different field?

好久不见. 提交于 2020-01-07 05:48:31
问题 I have got two tables named " studentBio " and " subjects ". Fields of both tables are being given below(with some values): On the form i have got something like this: AND in checkedlistbox1 i am showing corresponding subjects in the form like A+B+C. Which after retrieving from user would be split on the basis of '+' and be added into subjects table all at once. Fields of studentBio table are given as follows: WHERE (RollNo, RegYear,program, and faculty combine to make composite primary key):

MySQL combine UPDATE and SELECT query

爷,独闯天下 提交于 2020-01-07 05:27:22
问题 I have the following SELECT statement that returns data, example below: SELECT performers.ID, performers.Name, COUNT(*) AS CountOfDeals, COUNT(DISTINCT(deals.Name)) AS CountOfAliases FROM deals RIGHT JOIN performers ON deals.name LIKE CONCAT('%', performers.name, '%') WHERE performers.ID IN ( 27952, 27951, 27950, 27949, 27948 ) GROUP BY Name; Example data returned: ID Name CountOfDeals CountOfAliases 27952 Christine Hoberg 1 0 27951 Indian Jewelry 1 0 27952 Kinky Friedman 5 3 27949 KJ-52 1 0

PHP SQL updating product in multiple category

冷暖自知 提交于 2020-01-07 04:13:05
问题 I want to add product in multiple categories in php. After lot of search/research on this I am able to add products in multiple categories but its not working while updating/changing product categories on update page . MY DB structure is as: PRODUCTTABLE _____________________________________________ | pid | pname | price | pdetails | -----------+---------------+-------+----------+ CATEGORYTABLE ______________________________________ | id | catname | catslug | -----------+---------------+-----

Store old data in one column and update new data in another column within same table

白昼怎懂夜的黑 提交于 2020-01-07 02:51:06
问题 I'm not a professional programmer but an enthusiast who needs help. Here is my challenge: I have a table full of data for our employees. Currently, any of our employees can go to the "Update" web page on our web site and type in his new last name over the previous one that is displayed in a textbox and click submit, his last name will be updated in the database. However, my supervisor wants to keep the employees' previous last name in the same table as the new last name. Her idea is when an

Column ' ' in field is ambiguous

六眼飞鱼酱① 提交于 2020-01-07 02:44:11
问题 Im working with MySQL in java. I'm trying to update the 'owners' field in one of the tables 'regApartmentsTable', 'gardApartmentsTable', 'penthousesTable', which is empty, and corresponds to specific apartmentNum and street, and replace it with the string 'newOwners'. In order to do that I've wrote the following code: st=connection.prepareStatement("UPDATE regApartmentsTable,gardApartmentsTable,penthousesTable SET owners=? " + "WHERE owners=? AND apartmentNum=? AND street=?"); st.setString(1,

Strange variable overwrite in foreach loop

亡梦爱人 提交于 2020-01-06 19:33:43
问题 This must be something ugly obvious, but I'm stucked on this and can't solve it for past two hours. I have this piece of code: foreach($idMap as $menuId=>$pageId) { echo('$this->update("menus_items", SET "link = /content/show?id='.$pageId.'" WHERE id = '.$menuId.');'."\n"); $this->update ( 'menus_items', array('link'=>'/content/show?id='.$pageId), array('id = '.$menuId) ); } echo part works as expected ( $pageId is different for each item, taken from $idMap ), while Yii's CDbCommand::update()

PHP/MySQL: Combine UPDATE queries?

送分小仙女□ 提交于 2020-01-06 18:05:06
问题 Stack Overflow. PHP and SQL novice here. As part of a multi-user private messaging system I've been trying to write to learn how to properly interact with a database through PDO, I have two separate queries that are executed when a user deletes a message, via a single function deleteMessage() : UPDATE messages SET s_deleted = 1 WHERE id = :id AND sender = :sender UPDATE messages SET r_deleted = 1 WHERE id = :id AND recipient = :recipient They work well enough to accomplish what I need but

mysql return results from update

拈花ヽ惹草 提交于 2020-01-06 16:53:10
问题 I want to select a bunch of rows from a mysql database and update the viewed attribute of those once selected (this is a kind of 'I have read these' flag). Initially I did something like this: update ( select a, b, c from mytable where viewed = '0' ) set viewed = '1'; This selects the rows nicely and updates their viewed attribute as required. But it does not return the selected rows from the subquery. Is there a clause I can add, or perhaps I need to store the subquery, etc...? I did