Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 782
  • Last Modified:

MySQL COunt and expression

Hello Experts,

I need help writng this Query...I would like to count the words in a colA then divide it by colB and finally multiply by col C.

Thanks in advance experts.
0
decoded
Asked:
decoded
  • 3
  • 3
2 Solutions
 
Julian HansenCommented:
Can you reword your question as it is not clear what you are asking.

then divide it by colB and finally multiply by col C

Do you mean the count of words in colB and colC?

Maybe give more information on what you are trying to achieve.
0
 
decodedAuthor Commented:
See below

colA                                colB                             colC
hello my expert.               2                               5

colA= 3 , colb=2, colc=5

So the expresion from the example above should look like:
3/2*5 =7.5
0
 
johanntagleCommented:
Try this:

SELECT ( (LENGTH(colA) - LENGTH(REPLACE(colA, ' ', ''))+1) / colB ) * ColC
FROM table

That's assuming anything that's in between spaces is a word.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
decodedAuthor Commented:
This working correctly however; for some reason the word count is way off. It give me a number of 1211 when its actually suppose to be 649.

Any ideas experts.
0
 
Julian HansenCommented:
We need to see the data that is resulting in an answer of 1211 and 649
0
 
decodedAuthor Commented:
When I use the mysql expression: (LENGTH(colA) - LENGTH(REPLACE(colA, ' ', ''))+1) I get a count of 1244 and when paste this text inside of Microsoft word i get a count 744.

Any ideas?



Samsung Electronics Co. (005930) plants andsuppliers in China employed underage workers, forced them towork overtime and exposed them to unsafe conditions, a New York-based labor group said as it increased scrutiny on the world'slargest seller of mobile phones and TVs. China Labor Watch discovered “severe labor abuses” at sixfactories owned and operated by Suwon, South Korea-basedSamsung, and two facilities of its suppliers, the group said ina report dated yesterday. The violations include forced overtimework amounting to more than 100 hours a month, unpaid work and11 to 12 hours of standing, it said. The workers, also subject to “verbal and physical abuse,”don't have any effective internal grievance channel, the groupsaid. Labor advocates are widening their monitoring ofelectronics factories in Asia to Samsung, Dell Inc. (DELL) and Hewlett-Packard Co. after suicides at a China plant of Apple Inc.supplier Foxconn Technology Group in 2010 increased attention onworking conditions. “Labor violations aren't restricted to Samsung and are aproblem in the electronics industry,” Kevin Slaten, a spokesmanfor China Labor Watch, said in a Bloomberg TV interview today. China Labor Watch is currently investigating a factory thatmakes products for companies including HP, Dell and MicrosoftCorp., Li Qiang, a New York-based director at the group, said ina phone interview through a translator. The group also willrecheck factories run by Samsung and its suppliers to determinewhether improvements have been made, Li said. ‘Inhumane Violations' “The treatment of Samsung's Chinese factory workers is farfrom model,” according to the report. “The list of illegal andinhumane violations is long.” The findings follow an August report from the group thatsaid a Chinese assembler contracted by Samsung used child labor,prompting the Korean company to broaden inspections of itssuppliers. Samsung “frequently” checks its factories and the companyisn't aware of instances of hiring underage workers, James Chung, a Seoul-based spokesman, said by phone today. The electronics maker has “zero tolerance” for child-labor violations at its suppliers and will stop doing businesswith any company found to hire minors, Chung said. The companyis aware that some workers in China volunteer to work extrahours and will take “additional steps to re-evaluate ourworking hour practices,” he said, declining to comment onwhether the company will raise wages. $250 Salary Samsung's labor audits on its contractors aren't accuratebecause factory owners learn about the inspections in advance,Slaten said in the interview. The eight plants investigated by CLW employed a combined24,000 workers making mobile phones, DVD players, mobiledisplays and air conditioners, the report said. The base salaryfor workers at a printer factory owned by Samsung is about$250 a month, the report said. The group said its investigators either posed as workers toenter the factories or interviewed workers outside. China Labor Watch said last month that seven childrenyounger than 16 were working in the factory of HEG Electronics(Huizhou) Co. that makes phones and DVD players for Samsung.Samsung conducted its own investigation and said this week itdidn't find any workers younger than 16. IBM, Dell Samsung said Sept. 3 it will conduct on-site inspections bythe end of this month on all 105 Chinese companies that makeproducts solely for the company. The company also plans to havethe Electronic Industry Citizenship Coalition, a Washington-based industry group, regularly check its own plants and all ofits suppliers in China from 2013. The EICC is a group monitoring industry supply chains, withelectronics and technology companies as members. Its currentboard members include officials from International BusinessMachines Corp., Dell, HP and Intel Corp., according to itswebsite. Foxconn, the Apple supplier targeted by human-rightsactivists after the suicides, has cut working hours and improvedsafety at a faster pace than it was required, the Fair LaborAssociation said in a report last month. Apple opened factories making its products to the FLA,becoming the first electronics company to join the Washington-based independent labor monitoring group. To contact the reporter on this story:Jun Yang in Seoul at jyang180@bloomberg.net To contact the editor responsible for this story:Michael Tighe at mtighe4@bloomberg.net                                                                                                                             Enlarge image                                                                                  Samsung China Workers Physically, Verbally Abused, Group Says                                                                                               SeongJoon Cho/Bloomberg                                                A Samsung Electronics Co. semiconductor plant stands in Yongin, South Korea. The findings follow an August report from the group that said a Chinese assembler contracted by Samsung used child labor, prompting the Suwon, South Korea-based company to broaden inspections of its suppliers.                                                                                                                A Samsung Electronics Co. semiconductor plant stands in Yongin, South Korea. The findings follow an August report from the group that said a Chinese assembler contracted by Samsung used child labor, prompting the Suwon, South Korea-based company to broaden inspections of its suppliers. Photographer: SeongJoon Cho/Bloomberg                         //                    //

Open in new window

0
 
Julian HansenCommented:
That's because what Microsoft Calls a word and what the formula calls a word are not the same thing.

The formula above finds the number of words (being a contiguous collection of non-space characters) whereas Microsoft word will count the actual valid words - and ignore symbols

This php code returns the same answer as you are getting above
$x = "Samsung Electronics Co. (005930) plants andsuppliers in China employed underage workers, forced them towork overtime and exposed them to unsafe conditions, a New York-based labor group said as it increased scrutiny on the world'slargest seller of mobile phones and TVs. China Labor Watch discovered “severe labor abuses” at sixfactories owned and operated by Suwon, South Korea-basedSamsung, and two facilities of its suppliers, the group said ina report dated yesterday. The violations include forced overtimework amounting to more than 100 hours a month, unpaid work and11 to 12 hours of standing, it said. The workers, also subject to “verbal and physical abuse,”don't have any effective internal grievance channel, the groupsaid. Labor advocates are widening their monitoring ofelectronics factories in Asia to Samsung, Dell Inc. (DELL) and Hewlett-Packard Co. after suicides at a China plant of Apple Inc.supplier Foxconn Technology Group in 2010 increased attention onworking conditions. “Labor violations aren't restricted to Samsung and are aproblem in the electronics industry,” Kevin Slaten, a spokesmanfor China Labor Watch, said in a Bloomberg TV interview today. China Labor Watch is currently investigating a factory thatmakes products for companies including HP, Dell and MicrosoftCorp., Li Qiang, a New York-based director at the group, said ina phone interview through a translator. The group also willrecheck factories run by Samsung and its suppliers to determinewhether improvements have been made, Li said. ‘Inhumane Violations' “The treatment of Samsung's Chinese factory workers is farfrom model,” according to the report. “The list of illegal andinhumane violations is long.” The findings follow an August report from the group thatsaid a Chinese assembler contracted by Samsung used child labor,prompting the Korean company to broaden inspections of itssuppliers. Samsung “frequently” checks its factories and the companyisn't aware of instances of hiring underage workers, James Chung, a Seoul-based spokesman, said by phone today. The electronics maker has “zero tolerance” for child-labor violations at its suppliers and will stop doing businesswith any company found to hire minors, Chung said. The companyis aware that some workers in China volunteer to work extrahours and will take “additional steps to re-evaluate ourworking hour practices,” he said, declining to comment onwhether the company will raise wages. $250 Salary Samsung's labor audits on its contractors aren't accuratebecause factory owners learn about the inspections in advance,Slaten said in the interview. The eight plants investigated by CLW employed a combined24,000 workers making mobile phones, DVD players, mobiledisplays and air conditioners, the report said. The base salaryfor workers at a printer factory owned by Samsung is about$250 a month, the report said. The group said its investigators either posed as workers toenter the factories or interviewed workers outside. China Labor Watch said last month that seven childrenyounger than 16 were working in the factory of HEG Electronics(Huizhou) Co. that makes phones and DVD players for Samsung.Samsung conducted its own investigation and said this week itdidn't find any workers younger than 16. IBM, Dell Samsung said Sept. 3 it will conduct on-site inspections bythe end of this month on all 105 Chinese companies that makeproducts solely for the company. The company also plans to havethe Electronic Industry Citizenship Coalition, a Washington-based industry group, regularly check its own plants and all ofits suppliers in China from 2013. The EICC is a group monitoring industry supply chains, withelectronics and technology companies as members. Its currentboard members include officials from International BusinessMachines Corp., Dell, HP and Intel Corp., according to itswebsite. Foxconn, the Apple supplier targeted by human-rightsactivists after the suicides, has cut working hours and improvedsafety at a faster pace than it was required, the Fair LaborAssociation said in a report last month. Apple opened factories making its products to the FLA,becoming the first electronics company to join the Washington-based independent labor monitoring group. To contact the reporter on this story:Jun Yang in Seoul at jyang180@bloomberg.net To contact the editor responsible for this story:Michael Tighe at mtighe4@bloomberg.net                                                                                                                             Enlarge image                                                                                  Samsung China Workers Physically, Verbally Abused, Group Says                                                                                               SeongJoon Cho/Bloomberg                                                A Samsung Electronics Co. semiconductor plant stands in Yongin, South Korea. The findings follow an August report from the group that said a Chinese assembler contracted by Samsung used child labor, prompting the Suwon, South Korea-based company to broaden inspections of its suppliers.                                                                                                                A Samsung Electronics Co. semiconductor plant stands in Yongin, South Korea. The findings follow an August report from the group that said a Chinese assembler contracted by Samsung used child labor, prompting the Suwon, South Korea-based company to broaden inspections of its suppliers. Photographer: SeongJoon Cho/Bloomberg                         //                    //";
$words = explode(' ', $x);
echo "There are " . count($words) . "words";

Open in new window

Result : There are 1244 words
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now