Need help on Sql command for count
Hi,
I have the following table.
Temp_Set Table
ID Names Action
1 John Delete
2 John Add
3 Mary Update
4 Sim Add
5 Sim Update
How do I do a SELECT sql command for count(names) > 1 ?
Please kindly advise me. Thank you very much.
It doesnt work when I do this
SELECT * FROM Temp_Set
HAVING Count(names) > 1
It prompts me the following error:
ORA-00937: not a single-group group function
00937.00000 - "not a single-group group function"
*Cause:
*Action:
Error at Line:16 Column:7i am not sure but you can try this:
SELECT B.* FROM
(SELECT NAMES, COUNT(1) CNT FROM TEMP_SET GROUP BY NAMES) A, TEMP_SET B
WHERE A.NAMES = B.NAME
AND CNT > 1
Similar Messages
-
Need help on SQL Statement for UDF
Hi,
as I am not so familiar with SQL statements on currently selected values, I urgently need help.
The scenario looks as follows:
I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
The SQL statement for the formatted search in field "Subgroup1" looks as follows:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1] T0 WHERE T0.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod])
It works fine.
However, I cannot find the right statement for the formatted search in field "Subgroup2".
Unfortunately this does NOT WORK:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT $[OITM.U_Subgroup1])
I tried a lot of others that didn't work either.
Then I tried the following one:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
Thanks so much in advance!!!!
Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
Please also ignore the strikes.Hello Dear,
Use the below queries to get the values:
Item Sub Group on the basis of Item Group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
Item Sub Group 1 on the basis of item sub group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
Sub group 2 on the basis of sub group 1
SELECT T0.[Name] FROM [dbo].[@SUBGROUP2] T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
this will help you.
regards,
Neetu -
Need help with SQL retrieval for previous month till current date
Hi ,
Need help generating statistics from previous month from date of enquiry till current date of enquiry.
and have to display it according to date.
Date of enquiry : 03/02/2012
Application Type| 01/01/2012 | 02/01/2012 | 03/01/2012 |...... | 31/01/2012 | 01/02/2012 | 02/02/2012 | 03/02/2012 |
sample1 20 30 40
sample 2 40 40 50
sample 3 50 30 30
Hope you guys can help me with this.
RegardsHi,
932472 wrote:
Scenario
1)If i run the query at 12 pm on 03/2/2012. the result i will have to display till the current day.
2)displaying the count of the application made based on the date.
Application type 01012012 | 02012012 | 03012012 | ..... 01022012| 02022012|03022012
sample 1 30 40 50 44 30
sample 2 35 45 55
sample 3 36 45 55Explain how you get those results from the sample data you posted.
It would help a lot if you posted the results in \ tags, as described in the forum FAQ. {message{id=9360002}
SELECT application_type as Application_type
, COUNT (CASE WHEN created_dt = sysdate-3 THEN 1 END) AS 01012012 (should be getting dynamically)
, COUNT (CASE WHEN created_dt = sysdate-4 THEN 1 END) AS 02022012
, COUNT (CASE WHEN created_dt = sysdate-5 THEN 1 END) AS 03022012
, COUNT (CASE WHEN created_dt = sysdate-6 THEN 1 END) AS 04022012
FROM table_1
GROUP BY application_type
ORDER BY application_typeThat's the bais idea.
You can simplify it a little by factoring out the date differences:WITH got_d AS
SELECT qty
, TRUNC ( dt
- ADD_MONTHS ( TRUNC (SYSDATE, 'MON')
, -1
) AS d
FROM table1
WHERE dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MON')
, -1
AND dt < TRUNC (SYSDATE) + 1
SELECT SUM (CASE WHEN d = 1 THEN qty END) AS day_1
, SUM (CASE WHEN d = 2 THEN qty END) AS day_2
, SUM (CASE WHEN d = 62 THEN qty END) AS day_62
FROM got_d
See the links I mentioned earlier for getting exactly the right number of columns, and dynamic column aliases. -
Need Help in SQL command LIKE !
Hi all,
plz go through the following sql statement :
select last_name
from employees
where last_name like '%a%e%' or last_name like '%e%a%';
This gives an output where the last_name contains a or e in it.
Now what would be the best solution to find the records in a table where last_name contains a,e,i,o,u (in anyorder). Do I need to write all the combinations ? Or is there any solution.
Thanks,
SandeepThnaks all for your help. However, the issue is not yet resolved.
Ok let me more clear.
Now consider a table called Employees which has a column called LAST_NAME.
All the last_names in that column are of 10-20 letters. I want to findout the names
which has the letters q,o,p,r,s (in anyorder).
What would be the SQL statment ? From my point of view, I have to use LIKE keyword and use different combinations like '%q%0%p%r%s' or '%o%p%q%r%s' .,.....etc.
Or do we have any other better solution ?
Thnaks a lot for your solutions -
Help with sql command for inventory cost change report
Inventory Cost Changes within date range.
Columns on report
Item LastDateChanged CurrentCost PriorCost
Source File-TransHst (Type 14 is inventory cost change)
example data
Type,Item,DtChg,Cost
14,15825,02/01/2014,357.00
14,45832,03/15/2014,95725.00
14,15825,10/01/2013,322.00
14,45832,06/22/2012,94632.00
example output needed
Item LastDateChanged CurrentCost PriorCost
15825 02/01/2014 357.00 322.00
Using Crystal Reports 2008 with Oracle Database
I cannot create sql to retrieve data to create report.
Need Item, Last Change Date, Current Cost and Prior Cost as output of sql
ThanksHI Jerry,
I don't know real syntax of your database, try below SQL, you may have to modify the syntax wherever it is required.
Select t.Item, Max(t.DtChg),(case when year(t.dtchg) = Year(sysdate) then t.Cost else 0) as currentCost,
(case when year(t.dtchg) = Year(sysdate)-1 then t.Cost else 0) as PriorCost
From TransHst t
Where Type=14
Group by t.Item
Thanks,
Sastry -
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. -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
What is the sql command for SELECT with OR condition
Hi
What is the correct sql command for doing select with or condition??
SELECT * from TempData
WHERE port = '123'
OR serialnumber = '555'
So if there is a port = 123 or if there is a serialnumber = 555, I will get a successful select.
Thanks for helping a newbie!!Hi
What is the correct sql command for doing select with
or condition??
SELECT * from TempData
WHERE port = '123'
OR serialnumber = '555'
So if there is a port = 123 or if there is a
serialnumber = 555, I will get a successful select.
Thanks for helping a newbie!!Make sure you bracket your OR conditions
eg
SELECT * from TempData
WHERE column = 'VALUE'
and port = '123'
OR serialnumber = '555'
is read as
SELECT * from TempData
WHERE (column = 'VALUE'
and port = '123' )
OR serialnumber = '555'
which is not the same as
SELECT * from TempData
WHERE column = 'VALUE'
and ( port = '123'
OR serialnumber = '555' ) -
Need help in developing BADI for IT0001
Hi All,
I need help in developing BADI for IT0001.
On IT0001 create or change, there is need to update IT0017 with following data from IT0001
-Company Code
-Cost center
-Business Area
-Begin and End Date.
Other fields from IT0017 need to be derived from Position and update in IT0017.
Please guide me how I can address this. I do not want to go for dynamic action, as it is not getting evoked during background jobs.
I am new to BADI development and will appreciate step by step instructions.
ThanksHi,
follow the below steps to achive
Steps:
1. Execute Business Add-In(BADI) transaction SE18
2. Enter BADI name i.e. HRPAD00INFTY and press the display
button
3. Select menu option Implementation->Create
4. Give implementation a name such as Z_HRPAD00INFTY
5. You can now make any changes you require to the BADI within this
implementation, for example choose the Interface tab there are 3 methods avialble
6. Double click on the method you want to change, you can now enter
any code you require.
7. Please note to find out what import and export parameters a
method has got return the original BADI definition
(i.e. HRPAD00INFTY) and double click on the method name
for example within HRPAD00INFTY contract is a method
8. When changes have been made activate the implementation
<b>Reward points</b>
Regards -
I need help scrolling and highlighting for a vast amount of pics that I'm trying to transfer. I have a macbook pro osx 10.5.8
I need help scrolling and highlighting for a vast amount of pics that I'm trying to transfer. I have a macbook pro osx 10.5.8
-
I am attempting to write a SQL command for a Crystal report that links tables from two different databases, both of them Progress databases.I keep getting syntax errors that the table from the other db (meaning not the one I opened in DB Expert) can't be found. If someone has experience with Progress or otherwise has any ideas it would be greatly appreciated.
I'm not familiar with Progress, but does it have something like MS SQL's OPENQUERY using Linked Servers (which allows you to query a different DB server from the one you're connected to)? If not, you'll probably have to use two different SQL Commands to base the report on, then use Crystal to link the returned data sets. (I'm assuming "a different database" means "a different database server", not a different database on the same server instance...)
HTH,
Carl -
I still need help with the Dictionary for my Nokia...
I still need help with the Dictionary for my Nokia 6680...
Here's the error message I get when trying to open dictionary...
"Dictionary word information missing. Install word database."
Can someone please provide me a link the where I could download this dictionary for free?
Thanks!
DON'T HIT KIDS... THEY HAVE GUNS NOW.oops, im sorry, i didnt realised i've already submitted it
DON'T HIT KIDS... THEY HAVE GUNS NOW. -
Need help with SQL for Pie Chart
I am trying to create a pie charge which would have 3 slices.
Following sql gives me the expected values when I run the sql command:
select
round(avg(CATEGORY_1 + CATEGORY_2 + CATEGORY_3 + CATEGORY_4 + CATEGORY_5),0) "OD Engagements",
round(avg(CATEGORY_6 + CATEGORY_7 + CATEGORY_13),0) "Talent Engagements",
round(avg(CATEGORY_8 + CATEGORY_9 + CATEGORY_10 + CATEGORY_11 + CATEGORY_12),0) "Other Engagements"
from OTD_PROJECT
where STATUS in ('Open','Hold')
I get 3 columns labeled: OD Engagements, Talent Engagements and Other Engagements with the correct averages based on the the data.
I have tried several ways to try to get this to work in the SQL for a pie chart, but keep getting the invalid sql message and it won't save. I also tried saving without validation, but no data is shown on the chart at all.
I want to have a pie, with 3 slices, one labeled OD Engagements with a value of 27, one labeled Talent Engagements with a value of 43 and one labeled Other Engagements with a value of 30. Then I want to be able to click on each pie slice to drill down to a secondary pie chart that shows the breakdown based on the categories included in that type.
Since I am not grouping based on an existing field I an unsure what the link and label values should be in the chart sql.You'll need something like the below. I have no idea what the URL for the drilldown needs to be. It should create an appropriate link in your app for the particular slice. Mainly the code below breaks the SQL results into three rows rather than three columns. It may well have a syntax error since I can't test.
select linkval AS LINK,
title AS LABEL,
calc_val AS VALUE
FROM (SELECT 'OD Engagements' AS title,
round(avg(CATEGORY_1 + CATEGORY_2 + CATEGORY_3 + CATEGORY_4 + CATEGORY_5),0) AS calc_val,
'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
from OTD_PROJECT
where STATUS in ('Open','Hold')
UNION ALL
SELECT 'Talent Engagements' AS title,
round(avg(CATEGORY_6 + CATEGORY_7 + CATEGORY_13),0) AS calc_val,
'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
from OTD_PROJECT
where STATUS in ('Open','Hold')
UNION ALL
SELECT 'Other Engagements' AS title,
round(avg(CATEGORY_8 + CATEGORY_9 + CATEGORY_10 + CATEGORY_11 + CATEGORY_12),0) AS calc_val,
'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
from OTD_PROJECT
where STATUS in ('Open','Hold')
); -
Need to adjust SQL query for left outer join in Crystal Reports 2008.
I need to change this SQL 2005 query.....
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id
WHERE
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
To this query in Crystal Reports Report Writer:
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id AND
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
I can't seem to get the left outer join function of Crystal Reports to emulate the same SQL query in SQL 2005. Any ideas on how I can create this same query in Crystal 2008?
Thanks,
Dominic
Edited by: Dominic Carissimi on Oct 28, 2008 7:55 PM
Edited by: Dominic Carissimi on Oct 28, 2008 7:56 PMIf you want the list of values for command level parameter then you need to add another command like
select PropertyField from table
and delete the links between this command and the existing command.
Now go to field explorer and edit the command level parameter and make it as dynamic and add the property field from newly added command.
Hope this helps!
Raghavendra -
I have a database with fields containing large amounts of text. I wish to be able to search the text in the database using a sql command. I have a number of problems:
1. I will not know in advance how many words the user will be searching for eg 'Holidays' or 'Holidays in England' so how can I split these up and search effectively?
2. What is the SQL command to use to check in the database field to see if it has any of the related strings?
Any help would be greatly appreciated.1.Use StringTokenizer to split the words in your search string
StringTokenizer st = new StringTokenizer("query_string"," ");
2.Suppose it has 2 tokens then, construct a query like this, (You can use st.countTokens() to get the token count)
Select * from table where col1 like '%token1%' or col1 like '%token2%'
Hope this helps.
Sudha
Maybe you are looking for
-
How can I create a right-to-left .pdf in MS Publisher with Acrobat Pro 9?
Hello. We have a specialized application, and I was unable to find an answer by searching. We need to create a right-to-left diglot (multi-language) Bible translation in MS Publisher. It will have Hebrew and/or Aramaic on the right hand side, and Eng
-
Trouble connecting LaserJet6p to Windows 7 64 bit computer using usb to parallel printer cable
The printer isn't responding at all--not even a test page. I've verified that the correct driver is installed and the computer does recognize the printer (even as the "default"). Any suggestions? The computer is working with my other printer throug
-
How to run an external monitor with lid closed
how to use an external monitor with the "lid" closed
-
Loading pl/sql scripts into OWB and running it
Hi, Does anyone have an example for loading and executing PL/SQL Scripts in OWB?. Thanks Mehdi
-
Prompts for old user's password when DL or updating apps?
I have a used IPhone 3G. I had signed out of previous user's account and made my own. Everything was fine, DL apps and suddenly I went to update an app and when prompted for password it is old user's email!? I do not understand as I've gone into sett