Sponsored Content
Full Discussion: SQL IF-THEN-ELSE issue
Top Forums Programming SQL IF-THEN-ELSE issue Post 302406951 by pondlife on Wednesday 24th of March 2010 09:12:14 AM
Old 03-24-2010
SQL IF-THEN-ELSE issue

Hi All,

I have a table with the following columns:

sysName, date, time, cpuNum, cpuPercentageBsy

There are multiple system names and multiple CPU numbers.

I need to produce a report that shows the cpuPercentageBsy for cpuNum's 0 and 1 and then an average of cpuPercentageBsy for all the other CPU numbers.

I therefore need output that looks something like this:

sysName, date, time, CPU 0 Percentage Bsy, CPU 1 Percentage Bsy, Average CPU Busy all other CPU's

I can't even get started with this one so any help would be very much appreciated Smilie

Thanks,

p.

---------- Post updated at 01:12 PM ---------- Previous update was at 12:26 PM ----------

What I've got so far:

Code:
SELECT t1.sysName, t1.date, t1.time, 

  (CASE WHEN t1.cpuNum = 0 THEN t1.cpuPercentageBsy end) AS cpu0percBsy, 
  (CASE WHEN t1.cpuNum = 1 THEN t1.cpuPercentageBsy end) AS cpu1percBsy 

FROM CPU AS t1 INNER JOIN CPU AS t2 

ON t1.time = t2.time AND t1.date = t2.date

WHERE t1.date = curdate()-1 AND t1.cpuNum IN (0,1) 
   
   AND t1.sysName = 'SYS1' 
   
   AND t1.time BETWEEN '01:00:00' AND '02:00:00'

GROUP BY t1.froms;


And this gives me:

Quote:
+---------+------------+----------+-------------+-------------+
| sysName | date | time| cpu0percBsy | cpu1percBsy |
+---------+------------+----------+-------------+-------------+
| SYS1| 2010-03-23 | 01:00:00 | 32.683 | NULL |
| SYS1| 2010-03-23 | 01:05:00 | 32.846 | NULL |
| SYS1| 2010-03-23 | 01:10:00 | 33.181 | NULL |
| SYS1| 2010-03-23 | 01:15:00 | 32.558 | NULL |
| SYS1| 2010-03-23 | 01:20:00 | 31.841 | NULL |
| SYS1| 2010-03-23 | 01:25:00 | 31.833 | NULL |
| SYS1| 2010-03-23 | 01:30:00 | 31.541 | NULL |
| SYS1| 2010-03-23 | 01:35:00 | 31.110 | NULL |
| SYS1| 2010-03-23 | 01:40:00 | 30.627 | NULL |
| SYS1| 2010-03-23 | 01:45:00 | 30.015 | NULL |
| SYS1| 2010-03-23 | 01:50:00 | 31.780 | NULL |
| SYS1| 2010-03-23 | 01:55:00 | 31.813 | NULL |
| SYS1| 2010-03-23 | 02:00:00 | 32.903 | NULL |
+---------+------------+----------+-------------+-------------+
?
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SQL scripts not running, possible timeout issue?

I am a novice Unix scripter and need a little advice/help on a script I've written that's causing some problems. We are using Solaris 9 on a Sun box and the script is invoked with the korn shell. I have a two-part question: I wrote a shell script that calls and executes 3 separate sql scripts,... (3 Replies)
Discussion started by: E2004
3 Replies

2. Programming

SQL Issue please respond !!!

Hi Folks, I have a issue regards space in the records. Example: 999207404 |sp818056|STEVEN |LAWRENCE |Mike.S.Lawrence@sprint.com |2003 S Data Sales Mgr 77 |SVC ... (5 Replies)
Discussion started by: Haque123
5 Replies

3. Shell Programming and Scripting

KSH script SQL timeout issue

Hi all, I have a KSH script which is kicking off an sql scripts as follows: /usr/local/installs/instantclient_10_2/sqlplus -s username/password @$sql_path/sql_query.sql > $tmp_path/sql_query_results The problem I have is that sometimes the 10g Oracle Database spits out an error saying... (4 Replies)
Discussion started by: Donkey25
4 Replies

4. Programming

SQL Developer JOINS / GROUP BY issue.

Am having a nightmare with a certain piece of code.. have tried almost everything and just cannot see what the issue is.. CREATE OR REPLACE VIEW TOP_EARNER_PER_LOCATION AS SELECT E.FIRST_NAME || ' ' || E.LAST_NAME AS EMPLOYEE_NAME, L.REGIONAL_GROUP AS REGIONAL_GROUP, ... (1 Reply)
Discussion started by: U_C_Dispatj
1 Replies

5. Shell Programming and Scripting

Issue in SQL Loader scripts

Hi, I'm planning to load the data from FLAT files into tables. Source file: more input.txt LRNO|Bale|Horsepower|NumberOfBarges|BollardPull|NumberOfCars|GasCapacity|GrainCapacity|IndicatedHorsepower|LiquidCapacity|... (6 Replies)
Discussion started by: shyamu544
6 Replies

6. Shell Programming and Scripting

Sql issue in shell scripting

HI friends , i am also facing an issue in mysql i ma trying to insert detail in a variable but not got success #!/bin/sh mysql -u<username> -p<password> <dbname> << EOF DEV=`mysql --skip-column-names <dbname> -e "SELECT timestamp from process_record where id = 1"` EOF echo $DEV ERROR... (3 Replies)
Discussion started by: sanjay833i
3 Replies

7. Shell Programming and Scripting

Issue with SQL UNIX shell script -

Hi all I am writing a shell script which will run a select query from a table . If the ouput is not 500 - then send a email to the team saying there is a error . But i am not sure how to redirect this output of the select query to the log file - #!/bin/ksh sqlplus /nolog conect... (1 Reply)
Discussion started by: honey26
1 Replies

8. Shell Programming and Scripting

Issue with quotes when running SQL command from within su -c

RHEL 6.2/Bash shell root user will be executing the below script. It switches to oracle user logs in using sqlplus and tries to run the below UPDATE statement. All the commands after su -c are enclosed in a single quote delimited by semicolon. The execution has failed because the quotes... (3 Replies)
Discussion started by: omega3
3 Replies

9. Shell Programming and Scripting

awk concatenation issue - SQL generation

Greetings Experts, I have an excel file and I am unable to read it directly into awk (contains , " etc); So, I cleansed and copied the data into notepad. I need to generate a script that generates the SQL. Requirement: 1. Filter and select only the data that has the "mapping" as "direct"... (4 Replies)
Discussion started by: chill3chee
4 Replies
CPU(8)							      System Manager's Manual							    CPU(8)

NAME
cpu - A tool for user and group administration SYNOPSIS
cpu [OPTIONS] DESCRIPTION
CPU is a tool for user administration, that was initially based on FreeBSD's pw(8). This tool will allow you to administer users and groups on several different backends currently including LDAP and flat files. Please see the website http://cpu.sourceforge.net for more informa- tion, or help improve the man page. OPTIONS
There are two kinds of options; options for CPU and options for CPU modules. There are only four options for CPU, they are as follows: -C configfile, --config configfile The configuration file to be used by CPU. The options in this file are used for CPU modules. -h, --help Display help for CPU. If specified in conjunction with the -m option the help for that particular module is displayed. -M method, --method=method This is the method of administration. Current options are ldap or passwd (passwd is not yet working). This can be specified in the configuration file. -V, --version Display the version of the software. SEE ALSO
cpu.conf(5) cpu-ldap(8) AUTHORS
Blake Matheny <bmatheny@purdue.edu> The current version of this software is always availabe at http://cpu.sourceforge.net BUGS
To report a bug or problem, please e-mail: cpu-users@lists.sourceforge.net TODO
See TODO file that accompanied software. Please e-mail us with any additional suggestions. 17 February 2003 CPU(8)
All times are GMT -4. The time now is 06:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy