Need Help Writing a Query.
OK, i have been trying to write a query now and have gone in several different directions and find myself stuck back at square one and was hoping someone could help me out.
Here is my issue and i'll try to explain as best as i can.
Example: i have the following data.
Desc 1 --- Instruct 1 --- 2/2/2009
Desc 1 --- Instruct 1 --- 2/7/2009
Desc 1 --- Instruct 1 --- 2/3/2009
Desc 1 --- Instruct 2 --- 2/5/2009
Desc 2 --- Instruct 1 --- 2/3/2009
Desc 2 --- Instruct 1 --- 2/1/2009
What i need to do is write a query that will show distinct Descriptions as well as distinct instructions. (Example, Desc 1 could have 7 different instructions, so i would need 7 different lines for Desc 1, with the most recent date and a count for how many occurances of each specific instruction, for each specific Description for each of the 7 lines for Desc 1.
Example of results would be like this
Desc 1 --- Instruct 1 --- 2/7/2009 --- 3
Desc 1 --- Instruct 2 --- 2/5/2009 --- 1
Desc 2 --- Instruct 1 --- 2/3/2009 --- 2
Hopefully that is enough information, but if anything else is needed for me to provide in order to get some help, just let me know and i will do my best to get that information.
thanks in advance
Frank Kulash wrote:
Hi,
SELECT description
, instruction
, MAX (dt) AS most_recent
, COUNT (*) AS total_num
FROM table_x
GROUP BY descrrption
, instruction;"GROUP BY x, y" means the output will contain one row for every distinct combination iof x and y that occurs in the results.
All the columns in the SELECT BY clause must be
(a) in the GROUP BY clause,
(b) aggregate functions (like MAX or COUNT), or
(c) trivially dependant on (a) or (b) (for example: UPPER (description))Thank you;
I think i was trying to over complicate things.
So simple, yet so very effective
thanks again
Similar Messages
-
Need help writing a query for following scenario
Hi all, I need some help writing a query for the following case:
One Table : My_Table
Row Count: App 5000
Columns of Interest: AA and BB
Scenario: AA contains some names of which BB contains the corresponding ID. Some
names are appearing more than once with different IDs. For example,
AA BB
Dummy 10
Me 20
Me 30
Me 40
You 70
Me 50
Output needed: I need to write a query that will display only all the repeating names with their corresponding IDs excluding all other records.
I would appreciate any input. ThanksIs it possible to have a records with the same values for AA and BB? Are you interested in these rows or do you only care about rows with the same value of AA and different BB?
With a slight modification of a previous posting you can only select those rows that have distinct values of BB for the same value of AA
WITH t AS (
SELECT 'me' aa, 10 bb FROM dual
UNION ALL
SELECT 'me' aa, 20 bb FROM dual
UNION ALL
SELECT 'you' aa, 30 bb FROM dual
UNION ALL
SELECT 'you' aa, 30 bb FROM dual
SELECT DISTINCT aa, bb
FROM (SELECT aa, bb, COUNT(DISTINCT bb) OVER(PARTITION BY aa) cnt FROM t)
WHERE cnt > 1; -
Need help writing a query that generates sequential tokens
Updated example to accomodate duplicates in cacard and to change the #temp_tokentable.cccard to varchar(20).
I am just having a block. I have a should be easy task, and have looked at it several ways, but cannot come up with some tsql that I would not be embarressed to show coworkers.
This is a the simplistic example of what needs to get done -
cacard table has credit cards. need to replace all credit cards with a generated token. the token is generated by just adding 1 to the lasttokenused and then + the right(creditcard, 4). Then the token and clear credit card values are inserted into
tokentable.
cacard can be a rather large table (# of rows and wide) in production so need to be as efficient as possible. But it is a onetime conversion program.
Thanks for any help
IF OBJECT_ID('tempdb..#Temp_cacard') IS NOT NULL
DROP TABLE #Temp_cacard
IF OBJECT_ID('tempdb..#Temp_tokentable') IS NOT NULL
DROP TABLE #Temp_tokentable
IF OBJECT_ID('tempdb..#Temp_lasttokenused') IS NOT NULL
DROP TABLE #Temp_lasttokenused
Create table #temp_cacard (ccard numeric(19,0))
Insert into #temp_cacard values (1234567891234567), (2344567890123456789),(3456789012345678900), (1234567891234567)
Create table #temp_tokentable (token varchar(20), ccard varchar(20))
Create table #temp_lasttokenused (token varchar(20))
Insert into #temp_lasttokenused values ('081111111111111111')
want to end up with
CACARD
08111111111111124567
08111111111111136789
0811111111111114890008111111111111124567
tokentable
08111111111111124567 1234567891234567
08111111111111136789 2344567890123456789
08111111111111148900 3456789012345678900
lasttokenused
0811111111111114Thought that I would post the code that reads a credit card number file and replaces card numbers
with token values. The tokens keep the last 4 of the original credit card number. I have two example card number tables. One table -cacardn - has a numeric(19,0) card number and the other - cacardv - has a varchar(20) card
number. My shop has credit card numbers defined as both. Obviously, another step after this runs is to encrypt the #token.data column.
IF OBJECT_ID('tempdb..#cacardn')IS NOT NULL
DROP TABLE #cacardn;
IF OBJECT_ID('tempdb..#cacardv')IS NOT NULL
DROP TABLE #cacardv;
IF OBJECT_ID('tempdb..#Token')IS NOT NULL
DROP TABLE #Token;
IF OBJECT_ID('tempdb..#Temp_Token')IS NOT NULL
DROP TABLE #Temp_Token;
IF OBJECT_ID('tempdb..#LastToken')IS NOT NULL
DROP TABLE #LastToken;
-- cardnumber table that has numeric (19,0) card numbers
Create Table #cacardn ([cccard] numeric(19,0))
INSERT INTO #cacardn ([cccard]) VALUES
(NULL),
(0),
(1111),
(91111111111121112),
(1111),
(1113),
(91111111111201120);
-- carnumber table that has varchar(20) card numbers
Create Table #cacardv ([cccard] varchar(20))
INSERT INTO #cacardv ([cccard]) VALUES
(NULL),
('0'),
('00000000000000001111'),
('00091111111111121112'),
('00000000000000001111'),
('00000000000000001113'),
('00091111111111201120');
-- token table that has tokens, varbinary card numbers, data type (13-20) are card numbers
Create Table #Token (
[token] varchar(20),
[data] varbinary(256),
[type] int)
INSERT INTO #Token ([token],[data],[type]) VALUES
('00000000000000000000', CAST('00000000000000000000' as varbinary), 13),
('', CAST('' as varbinary), 13),
('0', CAST('0' as varbinary), 13),
('00091111111111111111', CAST('00000000000000001111' as varbinary), 13),
('00091111111111121112', CAST('00000000000000001112' as varbinary), 14),
('00091111111111201120', CAST('00000000000000001120' as varbinary), 20)
-- Temporary, Intermediate table
CREATE TABLE #Temp_Token(ClearValue varchar(128));
SELECT * INTO #LastToken from (
SELECT '0009111111111150') d (lastgeneratedToken)
-- Create an entry in the Temp_Token table for entries in the card number field that do not match the Token table token or
-- Token table data values. These must be card number clear values.
-- ++ change from #cacardv to #cacardv to test both numeric and varchar card numbers
-- ++ the card number field must not NULL, not = 0 and numberic values
INSERT INTO #Temp_Token
SELECT DISTINCT cccard
FROM #cacardv l
WHERE cccard IS NOT NULL and CAST(cccard as varchar) <> '0' and CAST(cccard as varchar) not like '%[^0-9]%' and
NOT EXISTS (SELECT 1 FROM #Token s
WHERE (right('00000000000000000000'+ rtrim(cccard), 20) = [token] or
CAST(right('00000000000000000000'+ rtrim(cccard), 20) as varchar) = CAST([data] as varchar)) and
[type] in (13,14,15,16,20))
DECLARE @lastgeneratedToken varchar(20) = (SELECT lastgeneratedToken from #LastToken)
-- Update the last token used
UPDATE ifs_EDLastTokenUsed
SET EDToken = RIGHT('0000000000000000' + CAST(@lastgeneratedToken + CAST(@@RowCount AS numeric)AS varchar), 16);
-- Insert into the Token table
INSERT INTO #Token
SELECT DISTINCT RIGHT('0000000000000000' + CAST(@lastgeneratedToken + ROW_NUMBER() OVER (ORDER BY ClearValue) AS varchar(20)) + RIGHT(ClearValue,4), 20),
CAST(RIGHT('0000000000000000' + ClearValue, 20) as varbinary), 13
FROM #Temp_Token
-- Now Update the card number field that matches the Token data field with the Token token field.
-- ++ change from #cacardv to #cacardv to test both numeric and varchar card numbers
-- ++ Do not undate NULL, 0, or non-numeric card numbers (they are invalid values)
UPDATE c
SET c.cccard = s.[token]
FROM #cacardv c inner join (SELECT DISTINCT cccard, Cast([token] as varchar) as [Token]
FROM #cacardv l inner join #Token s
ON RIGHT('0000000000000000' + CAST(l.cccard as varchar), 20) = CAST(s.[Data] as varchar)
WHERE [type] in (13,14,15,16,20)) s
on c.cccard = s.cccard
WHERE c.cccard IS NOT NULL and CAST(c.cccard as varchar) <> '0' and CAST(c.cccard as varchar) not like '%[^0-9]%'
-- Check the Results
select * from #cacardv
Any comments or suggestions would be appreciated. (this is not the exact code. but the main statements are represented.)
Wonder about my WHERE clauses that seek to exclude junk data (IS NOT NULL, <> '0', and numeric only data), shhould the WHERE close be on the inner or outer WHERE? -
i am trying to write sql query for a single recordset.
I have an items table with all the standard item info and an item_colorID.
i have a color_lookup table with 2 columns, item_colorID and color_ID
i have a colors table with 2 columns, color_ID and color
i want to join the tables and filter it so that a repeat region shows dynamic data of item name, description, thumb, price
and also a list/menu dynamically populated by color
filtered so that each item shows in the list/menu only the colors that the item has available.
i have tried different variations of this sql
SELECT * FROM items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName
but the list/menu shows every color choice multiplied by the number of items in that color
ie White will show 80+ times.
thanks for your help,
jim balthropbregent,
thanks for your help.
I am building a shopping cart and i have a recordset to list the items and a repeat region for that recordset
i have a second recordset for the colors joined to the item_colorID nested inside the repeat region.
the shopping cart software has a 'lookup from recordset' choice for the add to cart servior behavior
and then i bind to the columns on the cart page.
it produces this code
if (isset($totalRows_rs_itemscat3) && $totalRows_rs_itemscat3 > 0) {
$row_rs_itemscat3 = WAEC_findRecordMySQL($rs_itemscat3, "item_ID", $ATC_itemID);
if ($row_rs_itemscat3) {
$ATC_itemName = "".$row_rs_itemscat3['itemName'] ."";// column binding
$ATC_itemDescription = "".$row_rs_itemscat3['itemShortDesc'] ."";// column binding
$ATC_itemWeight = floatval("".$row_rs_itemscat3['itemWeight'] ."");// column binding
$ATC_itemQuantity = "".$_POST["Farrington_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_rs_itemscat3['itemPrice'] ."");// column binding
$ATC_itemThumbnail = "".$row_rs_itemscat3['itemThumb'] ."";// column binding
$ATC_itemcolorchoice = "".$row_rs_colors['color'] ."";// column binding
mysql_data_seek($rs_itemscat3, 0);
$row_rs_itemscat3 = mysql_fetch_assoc($rs_itemscat3);
the column binding for the colors is from a different recordset and when redirecting to the cart page the color info will not show.
So my thinking is if i could get the color list/menu to populate from the same recordset as the item listing, it would solve my add to cart server behavior.
Is it possible to do this with only one recordset?
the products page and the cart page can be seen
http://www.farrington-enterprises.com/rain-gutters.php
add an item to the cart with any color choice and the color info does not carry to the cart. -
Need Help writing cfloop query
I have a form with variables in it that is a duplicate. For
example I have id1, id2, id3. I have a loop and query set up like
this:
<cfloop index="i" from="1" to="3">
<cfquery name="insert_info" datasource="#dsn_slave#">
INSERT INTO new_samples (email, id, od, id_min, id_max,
cs_min, cs_max, material, durometer, quantity, units_of_measure,
timestamp) VALUES (#email#, #id#, #od#, #id_min#, #id_max#,
#cs_min#, #cs_max#, #material#, #durometer#, #quantity#, #measure#,
#CreateODBCDateTime(Now())#)
</cfquery>
</cfloop>
How do I set up id1 in the loop meaning how do I write it to
use my index=i so that it will add the 3 sets of values?Assuming that you're form fields are required, validated,
checked for their existence, etc., you could take the following
approach:
<cfloop from="1" to="3" index="i">
<cfquery name="instForm" datasource="dsn">
INSERT INTO new_samples (email)
VALUES ('#FORM["email"&i]#')
</cfquery>
</cfloop>
Naturally, add in the other fields...I'm too lazy to write
the whole query :)!
Hope this helps!
Craig -
Need Help on below Query.
Hi All,
Need Help on below Query.
Consider,
"test9" Table Data in COLUMN "Name" AS
Name
=====
'a'
'b'
'c'
'd'
'e'
I am writing a query as :
SELECT * FROM test9 WHERE Name IN ('a','b','c','d','e','f','g')
I want result set as , It should show data as -
'f'
'g'
i.e. data which does not exists in the table and which is give in in clause
Is it possible in a single query.You can put the data that is to be checked for into a table instead or an inline view, for example:
with t as
(select 'a' as c1 from dual
union all
select 'b' from dual
union all
select 'c' from dual
union all
select 'd' from dual
union all
select 'e' from dual)
select c1 from (select 'a' as c1 from dual
union all
select 'b' from dual
union all
select 'c' from dual
union all
select 'd' from dual
union all
select 'e' from dual
union all
select 'f' from dual
union all
select 'g' from dual)
minus
select c1 from t
C
f
g
2 rows selected. -
Need help writing host program using LabView.
Need help writing host program using LabView.
Hello,
I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
Any help would be appreciated.
Regards, George
George Dorian
Sutter Instruments
51 Digital DR.
Novato, CA 94949
USA
[email protected]
m
(415) 883-0128
FAX (415) 883-0572George may not answer you. He hasn't been online here for almost eight years.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Please, need help with a query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_dateTake a look on the syntax :
max(...) keep (dense_rank last order by ...)
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#i1000901
Nicolas. -
Please need help with this query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_datePerhaps something like this...
select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
from (
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id,
max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
where create_date = max_create_date
order by create_date -
I need help writing a script that finds the first instance of a paragraph style and then changes it
I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style. I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style. Any help would be greatly appreciated, thanks!
Hi,
Do you mean first instance of the paragraph style
- in a chosen story;
- on some chosen page in every text frames, looking from its top to the bottom;
- in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
If story...
You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
so:
Story.findText()[0].appliedParagraphStyle = Style_1;
//==> this will change a paraStyle of 1st occurence of story to "Style_1".
If other cases...
You would need to be more accurate.
rgds -
Need help writing small program!
Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
Directions:
Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.class CerealCompare {
public static void main(String[] args) {
// your code goes here
}Hope that helps.
P.S. Java does not have an if-then-else statement. -
Need Help Writing Server side to submit form via API
Hey
I need help writing a serverside application to submit
information via API to a separate server.
I have a client that uses constant contact for email
campaigns. We want to add to her website a form taht submits the
information needed to subscribe to her email list, to constant
contact via API.
FORM.asp :: (i got this one under control)
name
email
and submits to serverside.asp
SERVERSIDE.ASP
In serverside.asp i need to have
the API URL
(https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp)
username (of the constant contact account)
password (of the constant contact account)
name (submited from form.asp)
email (submitted from form.asp)
redirect URL (confirm.asp)
Can anyone help get me going in the right direction?
i have tried several things i found on the net and just cant
get anyone to work correctly.
One main issue i keep having is that if i get it to submit to
the API url correctly - i get a success code, it doesnt redirect to
the page i am trying to redirect to.
ASP or ASP.NET code would be find.
THANKS
sam> This does require server side programming.
> if you dont know what that is, then you dont know the
answer to my question. I
> know what i need to do - i just dont know HOW to do it.
If you are submitting a form to a script on a remote server,
and letting
that script load content to the browser, YOU have no control
over what it
loads UNLESS there is some command you can send it that it
will understand.
No amount of ASP on your server is going to change what the
remote script
does.
http://www.constantcontact.com/services/api/index.jsp
they only allow their customers to see the instructions for
the API so i
can't search to see IF there is a redirect you can send with
the form info.
But posts on their support board say that there is.
Alan
Adobe Community Expert, dreamweaver
http://www.adobe.com/communities/experts/ -
Hi everyone...
I need help with this query. The table 'cobros' has a primary key defined by id_cliente + id_cobro. I pretend to classify rows by COUNT(id_cobro) which are between a date range.
A client could have 1 or 2 or 3 rows per day, no more for a specific date. I would like to get first, all clients with COUNT(id_cobro) = 1, all clients with COUNT(id_cobro) = 2, and finally all clients with COUNT(id_cobro) = 3.
Something similar to:
1 SELECT id_cliente, COUNT(id_cobro) FROM cobros
2 WHERE fecha_proximo_cobro >= '2011-05-30 00:00'
3 AND fecha_proximo_cobro <= '2011-05-30 23:59'
4 AND COUNT(id_cobro) = 1
5 GROUP BY id_cliente
The fourth line is the problem. It doesn't work.
Thanks in advance!!!
MarioMaybe you are looking for something like this?
SELECT id_cliente
, COUNT(*) AS cnt
FROM cobros
WHERE fecha_promixo_cobro BETWEEN TO_DATE('2011-05-30 00:00','YYYY-MM-DD HH24:MI') AND TO_DATE('2011-05-30 23:59','YYYY-MM-DD HH24:MI')
GROUP BY id_cliente
ORDER BY 2
, 1Also, NEVER rely on implicit data type conversion as you have (you provide a STRING not a DATE).
Edited by: Centinul on Jun 2, 2011 12:36 PM
Fixed syntax error. -
Help needed in writing a Query/Procedure
Hello All,
Need all ur help in writing a query or procedure
Lets say the Table name is DEMO
There i have one column like num it has values
1
2
3
4
5
8
9
10
my query output should be
1-5
8-10
i,e .. if the diff between two rows is greater than 1 then it result should be in a separate group
I need a query/Procedure for this. Kindly help
Regards,
ChandraTried obtaining the output using SQL and the result is as follows:
SQL> WITH T AS
2 (
3 SELECT 1 COL1 FROM DUAL
4 UNION
5 SELECT 2 COL1 FROM DUAL
6 UNION
7 SELECT 3 COL1 FROM DUAL
8 UNION
9 SELECT 4 COL1 FROM DUAL
10 UNION
11 SELECT 5 COL1 FROM DUAL
12 UNION
13 SELECT 8 COL1 FROM DUAL
14 UNION
15 SELECT 9 COL1 FROM DUAL
16 UNION
17 SELECT 10 COL1 FROM DUAL
18 UNION
19 SELECT 13 COL1 FROM DUAL
20 UNION
21 SELECT 14 COL1 FROM DUAL
22 UNION
23 SELECT 15 COL1 FROM DUAL
24 UNION
25 SELECT 16 COL1 FROM DUAL
26 UNION
27 SELECT 23 COL1 FROM DUAL
28 UNION
29 SELECT 24 COL1 FROM DUAL
30 )
31 SELECT OUTPUT FROM
32 (
33 SELECT DECODE(COL3,NULL,COL1, COL2) || '-' || LEAD(DECODE(COL3,NULL,COL3, COL1)) OVER (ORDER BY DECODE(COL3,NULL,COL1, COL2)) OUTPUT FROM
34 (
35 SELECT COL1, LEAD(COL1) OVER (ORDER BY COL1) COL2, LAG(COL1) OVER (ORDER BY COL1) COL3 FROM T
36 )
37 WHERE
38 (COL2 - COL1 > 1 OR COL2 IS NULL OR COL3 IS NULL)
39 )
40 WHERE OUTPUT != '-';
OUTPUT
1-5
8-10
13-16
23-24
Maybe you are looking for
-
ATA190: Web GUI page options are greyed out
ATA190: Web GUI page options are greyed out and device failed registration to CM 10.5 do anyone have a resolution o this issue?
-
Performance and Resolution of AVCHD on hex core PC
If you can help with an unrelated issue, since Adobe 'Contact Us' notes that I should try the Forum because of a lengthy backup: I have a login problem on my hex core that was not used to download Production Premium CS6. I use my quad core backup PC
-
Dissolves imported from Premiere project not working in After Effects
When I import a Premiere project into After Effects all the dissolves turn into separate layers (black solids). There is no opacity information being imported for some reason.
-
I am new to Java world please somebody can help me to beggin forward if any Eng of you can give me a links or other resource please do that yours saed ismail H M
-
I downloaded a font a couple of days ago, and I noticed that the font is in my Itunes. I googled how to delete a font, and I did what it told me to do, but my computer isn't allowing me to delete this font. Why is it doing this, and how can I go ah