Solved

CONTINUE OF CORRECT ANSWER IN ID:39913692

Posted on 2014-03-07
5
343 Views
Last Modified: 2014-03-07
SELECT category cat1,
       cat cat2,
       COUNT(*) quantity,
       COUNT(CASE WHEN TYPE = 'P' THEN 1 END) type_p,
       COUNT(CASE WHEN TYPE = 'T' THEN 1 END) type_t
  FROM yourtable
GROUP BY category, cat
ORDER BY cat1, cat2 DESC;

Open in new window


Hi,

This works perfect for the answer work in that topic, what about if i want to create a column to count the respective fields that contain any of these words: rec, ric or roc. This is similar to the count(case... but i want to do something similar with a like for any of these three words, any idea?
0
Comment
Question by:joyacv2
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39913750
Not sure I follow but to use the same type of count with three words:

COUNT(CASE WHEN TYPE in ('rec','ric','roc') then 1 end)
0
 
LVL 1

Author Comment

by:joyacv2
ID: 39913757
Hi,

no work because the rec, ric, roc is a part of the string, not the complete string, this is something that i forget to mention
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39913782
>>this is something that i forget to mention

We cannot read minds...  ;)

then multiple 'or's?

COUNT(CASE WHEN TYPE like '%rec%' or TYPE like  '%ric%' or TYPE like  '%roc%') then 1 end)

move the wildcards however you need them.
0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39913795
yes, you cannot read minds, but can solve problems, jajaja, perfect solution!!! Thanks!!!!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39913867
You can use the percent sign for a wild card.

If you want to post the CREATE TABLE statement and a segment of code and data that will load the table, you will be able to get much faster answers, probably including complete code examples.  Just a thought...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now