<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>3cc Internet &#187; phpMyAdmin</title>
	<atom:link href="http://www.3cc.org/tag/phpmyadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3cc.org</link>
	<description>Simplifying sites</description>
	<lastBuildDate>Sat, 31 Dec 2011 15:51:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Simple Math &#8211; Updating MySQL Prices by a Percentage (And rounding)</title>
		<link>http://www.3cc.org/2009/01/simple-math-updating-mysql-prices-by-a-percentage-and-rounding/</link>
		<comments>http://www.3cc.org/2009/01/simple-math-updating-mysql-prices-by-a-percentage-and-rounding/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 22:46:25 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>
		<category><![CDATA[sql queries]]></category>
		<category><![CDATA[update prices by percentage]]></category>

		<guid isPermaLink="false">http://www.3cc.org/backyard/?p=9</guid>
		<description><![CDATA[The other day we had the simple request from a client &#8211; they asked us to update every price on their site. They asked us to increase their prices on ALL their products by 8%. This is a simple bit of SQL which updates all the numbers in a field by a percent. Let&#8217;s say [...]]]></description>
			<content:encoded><![CDATA[<p>The other day we had the simple request from a client &#8211; they asked us to update every price on their site. They asked us to increase their prices on ALL their products by 8%.</p>
<p>This is a simple bit of SQL which updates all the numbers in a field by a percent.</p>
<p>Let&#8217;s say our database is called catalog.</p>
<p style="padding-left: 30px;">Our table is called products.</p>
<p style="padding-left: 60px;">Our field is called products_price.</p>
<p>So the query on the catalog database would be:</p>
<p><strong>UPDATE products SET products_price = products_price * 1.08</strong></p>
<p>Simple! &#8216;UPDATE products&#8217; tells the database which table we&#8217;re talking about, and &#8216;SET products_price&#8217; will alter every value in the table in the &#8216;products_price&#8217; field.</p>
<p>Then, we say &#8216;products_price = products_price * 1.08&#8242;, which simply says that the each value for products_price will be 1.08 times the current value. As we know, a value * 1.08 is 8% bigger.</p>
<p>But wait! That&#8217;s given us some nasty prices &#8211; for example,</p>
<p><strong>523.99 * 1.08 = 565.9092</strong></p>
<p>4 decimal places? We could use the ROUND function to round our values to 2 decimal places.</p>
<p><strong>UPDATE products SET products_price = ROUND ( products_price , 2 )</strong></p>
<p>I&#8217;ve kept it in the same format as above so you can see how it is used. This will round all values to 2 decimal places. Now, to run both queries at the same time:</p>
<p><strong>UPDATE products SET products_price = ROUND ( products_price * 1.08 , 2 )</strong></p>
<p>Easy! That&#8217;s updated all your prices in a couple of seconds. This was run on a site using ZenCart &#8211; that&#8217;s where the database structure is from, while the query was run in phpMyAdmin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2009/01/simple-math-updating-mysql-prices-by-a-percentage-and-rounding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

