sql-update

Making select and update in one query

人走茶凉 提交于 2019-12-30 10:59:33
问题 is there a query where I can do both querys in one? This is the first $q = "select c.id as campaignId,c.priceFactor, o.cid,o.bloggerPrice,o.state as state,o.customerPrice,o.id as orderId,o.listPrice,o.basicPrice from campaign c, orders o where c.id={$campaignId} and c.id = o.cid and o.state in (8,9)"; And this is the second foreach($orders as $order) { $listPrice = $order->priceFactor * $order->basicPrice; if($order->bloggerPrice < $listPrice || $order->customerPrice < $listPrice) { $order-

table updates empty spaces when user do not enter anything to the textbox

本小妞迷上赌 提交于 2019-12-30 07:49:08
问题 i am doing a project where one may update the name, position, department and tag of the employee. But as i do my project, it wont update, i know there is something wrong with my code. would you guys mind checking it. my php page has an index.php which is the main menu, if you click the employee name in the list, a pop up window will appear. that pop up is for updating. my php code (it now updating) but errors found: <?php $con=mysql_connect('localhost','root','pss') or die(mysql_error());

Postgres INSERT ON CONFLICT DO UPDATE vs INSERT or UPDATE

回眸只為那壹抹淺笑 提交于 2019-12-30 06:05:04
问题 I have stock_price_alert table with 3 columns. stock_price_id is PRIMARY KEY & also FOREIGN KEY to other table. Table definition as below: create table stock_price_alert ( stock_price_id integer references stock_price (id) on delete cascade not null, fall_below_alert boolean not null, rise_above_alert boolean not null, primary key (stock_price_id) ); I need to either: 1) INSERT record if not exist -- query 1 INSERT INTO stock_price_alert (stock_price_id, fall_below_alert, rise_above_alert)

Postgres INSERT ON CONFLICT DO UPDATE vs INSERT or UPDATE

独自空忆成欢 提交于 2019-12-30 06:04:50
问题 I have stock_price_alert table with 3 columns. stock_price_id is PRIMARY KEY & also FOREIGN KEY to other table. Table definition as below: create table stock_price_alert ( stock_price_id integer references stock_price (id) on delete cascade not null, fall_below_alert boolean not null, rise_above_alert boolean not null, primary key (stock_price_id) ); I need to either: 1) INSERT record if not exist -- query 1 INSERT INTO stock_price_alert (stock_price_id, fall_below_alert, rise_above_alert)

Postgres INSERT ON CONFLICT DO UPDATE vs INSERT or UPDATE

被刻印的时光 ゝ 提交于 2019-12-30 06:04:38
问题 I have stock_price_alert table with 3 columns. stock_price_id is PRIMARY KEY & also FOREIGN KEY to other table. Table definition as below: create table stock_price_alert ( stock_price_id integer references stock_price (id) on delete cascade not null, fall_below_alert boolean not null, rise_above_alert boolean not null, primary key (stock_price_id) ); I need to either: 1) INSERT record if not exist -- query 1 INSERT INTO stock_price_alert (stock_price_id, fall_below_alert, rise_above_alert)

Django update queryset with annotation

家住魔仙堡 提交于 2019-12-29 16:25:24
问题 I want to update all rows in queryset by using annotated value. I have a simple models: class Relation(models.Model): rating = models.IntegerField(default=0) class SignRelation(models.Model): relation = models.ForeignKey(Relation, related_name='sign_relations') rating = models.IntegerField(default=0) And I want to awoid this code: for relation in Relation.objects.annotate(total_rating=Sum('sign_relations__rating')): relation.rating = relation.total_rating or 0 relation.save() And do update in

Update a table with a trigger after update

有些话、适合烂在心里 提交于 2019-12-29 08:55:31
问题 I have two tables batch (batch_id,start_date,end_date,batch_strength,is_locked) sem (user_id,is_active,no_of_days) I have executed the trigger procedure given below then update the table using query CREATE OR REPLACE FUNCTION em_batch_update() RETURNS trigger AS $em_sem_batch$ BEGIN UPDATE batch set is_locked='TRUE' where (start_date + (select no_of_days from sem WHERE is_active='TRUE' and user_id='OSEM') ) <= current_date; return NEW; END; $em_sem_batch$ LANGUAGE plpgsql; CREATE TRIGGER em

SQL - Update a table using a field of another table

爱⌒轻易说出口 提交于 2019-12-29 08:40:10
问题 I am trying to execute the following update query: UPDATE Commodities INNER JOIN UniqueCountries ON Commodities.wbCode = UniqueCountries.wbCode SET Idenb = UniqueCountries.wbName||yr The query is clearly wrong, as it doesnt work. How can I fix it? The query is supposed to update column IdenB with the concatenated value of wbName and yr ( wbName||yr ). However, wbName is on another table called UniqueCountries , which is why I tried to perform an Inner Join. What am I doing wrong and how can I

UPDATE statement in Oracle using SQL or PL/SQL to update first duplicate row ONLY

送分小仙女□ 提交于 2019-12-29 07:31:53
问题 I'm looking for an UPDATE statement where it will update a single duplicate row only and remain the rest (duplicate rows) intact as is, using ROWID or something else or other elements to utilize in Oracle SQL or PL/SQL? Here is an example duptest table to work with: CREATE TABLE duptest (ID VARCHAR2(5), NONID VARCHAR2(5)); run one INSERT INTO duptest VALUES('1','a'); run four (4) times INSERT INTO duptest VALUES('2','b'); Also, the first duplicate row has to be updated (not deleted), always,

UPDATE statement in Oracle using SQL or PL/SQL to update first duplicate row ONLY

南楼画角 提交于 2019-12-29 07:31:11
问题 I'm looking for an UPDATE statement where it will update a single duplicate row only and remain the rest (duplicate rows) intact as is, using ROWID or something else or other elements to utilize in Oracle SQL or PL/SQL? Here is an example duptest table to work with: CREATE TABLE duptest (ID VARCHAR2(5), NONID VARCHAR2(5)); run one INSERT INTO duptest VALUES('1','a'); run four (4) times INSERT INTO duptest VALUES('2','b'); Also, the first duplicate row has to be updated (not deleted), always,