How to count same record in a table
i have :
table A: id - name - code
but now i have so much same record by name, i want select all record by name have same name > 2, and count it . pls help me
Try:
WITH CTE AS (
SELECT Color, COUNT(*) OVER (PARTITION BY Color) AS Freq,
ROW_NUMBER() OVER (PARTITION BY Color ORDER BY (SELECT 1) ) AS RN
FROM Production.Product WHERE Color is not null)
SELECT Color, Freq FROM CTE WHERE RN=1
AND Freq > 1 ORDER BY Color;
Black 93
Blue 26
Multi 8
Red 38
Silver 43
Silver/Black 7
White 4
Yellow 36
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
Similar Messages
-
How can i fetch records from 3 tables in a single query without using join
Hi.
Can any body please tell me <b>How can i fetch records from 3 tables with a single query without using joins</b>
Thanx
prabhuduttaHi Prabgudutta,
We can fetch the data by using the views concept.
Go throuth this info we can know the how to create view and same like database table only we can fetch the data.
Views conatin the data at runtime only.
Four different view types are supported. These differ in the
way in which the view is implemented and in the methods
permitted for accessing the view data.
Database views are implemented with an equivalent view on
the database.
Projection views are used to hide fields of a table (only
projection).
Help views can be used as selection method in search helps.
Maintenance views permit you to maintain the data
distributed
on several tables for one application object at one time.
step by step creation of Maintenance view:
With the help of the table maintenance generator, you are able to maintain the ENTRIES of the table in SM30 transaction.
It can be set in transaction SE11 - Tools - Table maintenance generator.
Table maintanance Generator is used to manually input values using transaction sm30
follow below steps
1) go to se11 check table maintanance check box under attributes tab
2) utilities-table maintanance Generator-> create function group and assign it under
function group input box. Also assign authorization group default &NC& .
3) select standard recording routine radio in table table mainitainence generator to move table
contents to quality and production by assigning it to request.
4) select maintaience type as single step.
5) maintainence screen as system generated numbers this dialog box appears when you click on create button
6) save and activate table
One step, two step in Table Maintenance Generator
Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.
Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.
SM30 is used for table maintenance(addition or deletion of records),
For all the tables in SE11 for which Table maintenance is selected , they can be maintained in SM30
Sm30 is used to maintain the table ,i.e to delete ,insert or modify the field values and all..
It creates the maintenance screen for u for the aprticular table as the maintenance is not allowed for the table..
In the SE11 delivery and maintenance tab, keep the maintenance allowed..
Then come to the SM30 and then enter the table name and press maintain..,
Give the authorization group if necessary and give the function group and then select maintenance type as one step and give the screen numbers as system specified..
Then create,,,
Then u will able to see the maintenance view for the table in which u can able to insert and delete the table values...
We use SM30 transaction for entering values into any DB table.
First we create a table in SE11 and create the table maintenance generator for that Table using (utilities-> table maintenance generator) and create it.
Then it will create a View.
After that from SM30, enter the table name and Maintain, create new entries, change the existing entries for that table.
Hope this resolves your query.
Reward all the helpful answers.
Rgds,
P.Naganjana Reddy -
How to identify new records in a table using OBIEE
Hi,
I have price change table as and when a record comes into this table i have to generate an alert. Then show a report with the price changes on which i can invoke an action to go into my transactional system to make the chnage. And once the change is made the process again starts to look for any new price chnage records that are recieved.
Could anyone pls tell me how to identify new records in a table.
RgdsSELECT ID, LastName, FirstName,
RANK() OVER (PARTITION BY LastName,
FirstName ORDER BY ID) AS SeqNumber
FROM
(SELECT ID, LastName, FirstName
FROM Customers
WHERE (LastName, FirstName) IN
(SELECT LastName, FirstName
FROM Customers
GROUP BY LastName, FirstName
HAVING COUNT(*) > 1) -
Regarding how to delete the record in internal table
Hi experts ,
how to delete the record in intarnal table after validating the data,
if record contains invalid fields?
i am giving my code see this and give me the answer?
loop at it_data into wa_data .
Validate Cost Center
READ TABLE it_kostl INTO wa_kostl WITH KEY kostl = wa_data-kostl BINARY SEARCH.
IF sy-subrc NE 0.
PERFORM update_error_log USING wa_data
text-004.
ENDIF.
Validate source file material ( material number )
loop at it_mara into wa_mara .
read table it_ausp into wa_ausp with key atwrt = wa_data-i_matnr .
if sy-subrc NE 0 .
PERFORM update_error_log USING wa_data
text-002.
delete it_data-objek .
else.
read table it_mara into wa_mara with key matnr = wa_ausp-objek .
if sy-subrc EQ 0 .
wa_data-objek = wa_mara-matnr.
wa_data-matkl = wa_mara-matkl.
ENDIF.
Modify it_data from wa_data .
endif.
*endloop.
Validate unit of measure (unit)
READ TABLE it_t006 INTO wa_t006 WITH KEY msehi = wa_data-unit .
IF sy-subrc NE 0.
PERFORM update_error_log USING wa_data
text-003.
endif.
Validate delivery location ( storage location )
READ TABLE it_lgort INTO wa_lgort WITH KEY del_loc = wa_data-del_loc.
IF sy-subrc NE 0.
PERFORM update_error_log USING wa_data
text-001.
if wa_data-flag ='x' .
delete it_data from wa_data .
endif.
ENDIF.
endloop.Hi Naren,
First get the index number of the IT_data table and store it in one variable whose declaration like this.
data: tabix type sy-tabix.
while reading the internal table it_data set the tabix variable.
tabix = sy-tabix.
Instead of the above use below one.
Delete it_data-objek
Use the Below statement it will delete the row from the internal table.
Delete it_data-objek index tabix
Thanks,
Chidanand -
How to insert a record in ROOSPRMSC table? (accidentally deleted)
Calling an InfoPackage in BW causes short dump, while fixing the short dump issue, accidentally
deleted the "ROOSPRMSC" table entries.
Could you tell me how to insert a record in "ROOSPRMSC" table???Hi Senthil,
Regards,
Phani Raj Kallur
Message was edited by: Phani Raj Kallur -
How to count number of rows in table
can I get number of row in table except Count(*) in pl/sql
is there any other wayAlso posted and answered here
how to count number of rows in table
count(*) will be the fastest way. It is only slow if the table has a vast number of rows, in which case why do you need to know the tables has 73552436467721 rows and not 73552436467737 rows. It doesn't seem to be much use. Either that or you are counting them a lot, which again seems rather pointless. -
How to delete a record from BSEG table
Dear Experts,
How to delete a record from BSEG table.
If there possible to delete some records from transparent table ?
Please help.
Regards,
TanHi,
Deleting a record from a standard table can be done only if table maintenance exists - Cehck tcode - SM30. But it is not advisable to delete records, coz the records may be dependent on many other tables. If u delete in a single place, there may be chance that inconsistency in the data happens and hence will affect ur financial statements.
Pls. assign points, if useful
Regards,
Sridevi -
How to find varience records in two tables
Hi,
i have two tables like emp1, emp2
data in emp1:
empname empid add
alasta 10 ca
mark 20 nw
chews 30 jp
data in emp2:
empname empid add
alasta 10 ca
mark 20 nw
chews 30 jp
burgess 45 ngm
if u observe the above two tables data you can easily identify there is repeated data/duplicated data in both tables.
as there any way find out using comparison same records in two tables..........
if i write a query then i can easily understand the same data is existed in two tables
Thanks in advance....>
as there any way find out using comparison same records in two tables..........
>
>
if i write a query then i can easily understand the same data is existed in two tables
>
So, what is your problem now?
You can join both the tables using a simple query and get the records.
select e1.empname, e2. empname from emp1 e1, emp2 e2 where
e1.empname = e2.empname and e1.empid = e2.empid -
How to Restore deleted records in other table in oracle database 10g...
Hi All,
i want to restore deleted records of a particular table in other table
suppose:
i perform a query
delete from emp
where deptno =30;
now i wont to restore deptno=30 records in other table, let say in emp1 table
can any one let me know how to do it?
Thanks..This is what flashback query is for:
orclz> conn scott/tiger
Connected.
orclz> select count(*) from emp;
COUNT(*)
14
orclz> delete from emp where deptno=30;
6 rows deleted.
orclz> commit;
Commit complete.
orclz> create table deleted30 as select * from emp as of timestamp(systimestamp - 5/1440) where deptno=30;
Table created.
orclz> select count(*) from deleted30;
COUNT(*)
6
orclz> -
How to insert some records in one table and some records in another table
Interview question
how insert records in two tables by using trigger
CREATE or REPLACE TRIGGER Emp_Ins_Upd_Del_Trig
BEFORE delete or insert or update on EMP
FOR EACH ROW
BEGIN
if UPDATING then
UPDATE emp2
SET
empno = :new.empno,
ename = :new.ename
--, job = :new.job
--, mgr = :new.mgr
--, hiredate = :new.hiredate
, sal = :new.sal
--, comm = :new.comm
--, deptno = :new.deptno;
sdate = :new.sdate,
edate = :new.edate
end if;
if INSERTING then
INSERT INTO emp2
VALUES
( :new.empno
, :new.ename
--, :new.job
--, :new.mgr
--, :new.hiredate
, :new.sal
--, :new.comm
--, :new.deptno
new.sdate,
new.edate);
end if;
if DELETING then
DELETE FROM emp2
WHERE empno = emp2.empno;
end if;
END;
it is working fine but he wants to insert some specific litimit on one table and some specified limit of records in one ..
In this senerio can i insert records by use count of records...
please help me..Can you be more specific on the "Limit"
Conditional insert can be used in this case. -
How to Getting 10lack records from 2 tables and share into 10 tables
Hi Experts,
i have some special requirement about counting records before we we procees them in to intenal table.
here is the sample code .
**Needed to get users for ref users data
DATA: BEGIN OF gt_usr02 OCCURS 0,
bname LIKE usr02-bname,
END OF gt_usr02.
DATA:g_wa_usr02 LIKE LINE OF gt_usr02.
**Needed To get reference users data
DATA: BEGIN OF gt_usrefus OCCURS 0,
bname LIKE usrefus-bname,
refuser LIKE usrefus-refuser,
END OF gt_usrefus.
DATA:g_wa_usrefus LIKE LINE OF gt_usrefus.
SELECTION-SCREEN :BEGIN OF BLOCK blk1 WITH FRAME TITLE text-000.
SELECT-OPTIONS : s_user FOR usr02-bname.
SELECTION-SCREEN :END OF BLOCK blk1.
START-OF-SELECTION.
REFRESH:gt_usr02,gt_usrefus.
CLEAR:gt_usr02,gt_usrefus
CLEAR:g_wa_usr02,g_wa_usrefus ,
SELECT bname FROM usr02 INTO TABLE
gt_usr02 WHERE bname IN s_user. "say suppose "*" in s_user
1.Here i need to get no of records befor we are getting data from this select statement
basically i need to know the no of records (like count (sy-dbcnt) with same condition like below.
IF NOT gt_usr02 IS INITIAL.
SELECT bname refuser FROM usrefus INTO TABLE gt_usrefus
FOR ALL ENTRIES IN gt_usr02
WHERE bname = gt_usr02-bname AND refuser <> space.
ENDIF.
2.if i found no of records based on that i have to broke those records into diff tables
say i found 10,000 records ,that time i have spilt those 10,000 records into 10 tables(Similar strcture like table gt_usrefus ) with 1000 records each .
Can you help us.this requirement is for avoiding memory issues.Hi nagraju102,
- please try to post code formatted as code
- splitting a table of 10000 records into 10 tables of 1000 records will use not less memory at all, even a little bit more for the administrative overhead
- the numer of lines in an internal table can determinde used system function lines( itab )
- you can create an internal table of references and then create any number of internal tables,
data:
lt_tabref type table of ref to data.
field-symbols:
<table> type table,
<tabref> type ref to data.
DO 10 TIMES.
append initial line to lt_tabref assigning <tabref>.
create data <tabref> type table of usrefus.
assign <tabref>->* to <table>.
perform fill_table changing <table>."fill this table as you prefer
ENDDO.
Here you have 10 internal tables with USREFUS structure.
Regards,
Clemens -
How find just one record on the table
Hi,
I've this table TAB_DV:
COD_ID.........DV_ID
001............A
002............A
002............B
002............C
002.............
003............
004............GG
004............DD
004............FF
004............MM
004............TT
008.............BB
0022..............
0033..............
0044............A
0044............
0055............FF
0066............
I'd like to find only the COD_ID that have one record (in the table TAB_DV) without dv_id:
In my case:
COD_ID.........DV_ID
003............
0022..............
0033..............
0066............
If I run:
SELECT COD_ID, DV_ID
FROM TAB_DV
WHERE DV_ID IS NULL
GROUP BY COD_ID, DV_ID;
I get also COD_ID with more records.
How can I write this query?
Thanks in advance.try this
select cod_id
from tab_dv
where dv_id is null
having count(cod_id) = 1
group by cod_id
or
select t1.cod_id, t1.dv_id
from tab_dv t1
where t1.cod1 in (select cod_id
from tab_dv t2
having count(t2.cod_id) = 1
group by t2.cod_id)
and t1.dv_id is null -
How to insert same record multiple times in a loop..
Dear All,
I need to insert a record multiple time how it can be accomplish...
eg:
ref no name dept
123 abc 1
122 def 2
121 feg 1
120 hhh 2
while inserting into another table:
all dept no 1 with should inserted 3 times for each record above
final out put should be :
table abc
ref no name dept
123 abc 1
123 abc 1
123 abc 1
122 def 2
121 feg 1
121 feg 1
121 feg 1
120 hhh 2
Thank Youuser3029023 wrote:
Dear All,
I need to insert a record multiple time how it can be accomplish...
eg:
ref no name dept
123 abc 1
122 def 2
121 feg 1
120 hhh 2
while inserting into another table:
all dept no 1 with should inserted 3 times for each record above
final out put should be :
table abc
ref no name dept
123 abc 1
123 abc 1
123 abc 1
122 def 2
121 feg 1
121 feg 1
121 feg 1
120 hhh 2
Thank YouTry this .
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select '123' AS ref_no,'abc' AS name,'1' as Dept
3 from dual
4 union all
5 select '122','def','2' from dual
6 union all
7 select '333','feg','1' from dual
8 union all
9 select '120','hhh','2' from dual
10 )
11 select ref_no,name,Dept from t,(select level x from dual connect by level <4)
12* order by 1
SQL> /
REF NAM D
120 hhh 2
120 hhh 2
120 hhh 2
122 def 2
122 def 2
122 def 2
123 abc 1
123 abc 1
123 abc 1
333 feg 1
333 feg 1
333 feg 1
12 rows selected.And insert the same onto your desired table.
Hope this Helps..
Regards,
Achyut -
How to SELECT ALL records of a TABLE VIEW in the BSP page
Hi All,
In the BSP portal, I am displaying some data(multple records) in the form of a table using the BSP TAG <htmlb:tableView>. I wrote the logic in the 'VIEW' of the BSP application which will be triggered by the controller. I have used the attribute selectionMode = "MULTISELECT" to have a Check Box to select a row.
My requirement is to have a button/checkbox on the first column of the header of the table view. By clicking on this, it should select/desect all the records of the table. Could someone please help me how to do this? What attribute I should use in the tableview to get the button in the header row of the table and how to select all the records of the table.?
Please provide your valuable inputs.
Thanks & Regards,
Paddu.Select all / Deselect all functionality when onRowSelection is there
-
How to count number of ones in table
Hello,
i created one table 16x32 each cell is updating 1 byte of data,how to count number of one in all cell,and is it right way to calculate check sum??
thank youThe simplest way is to call GetTableCellRangeValues with VAL_ENTIRE_TABLE as the range, next summing array elements.
But I don't understand your comment on checksum, so this may not be the more correct method for your actual needs: can you explain what do you mean?
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos?
Maybe you are looking for
-
Residual Payment identification
Hi, How can we identify the payment document which was made through partial payment or residual payment F-53 in BSIK and BSAK tables. We need to develop a report based on paid history for the vendor. Some times we use residual payement method. But t
-
Aero Problems on Win 7 With PRE, PSE and OE
I am using nVideo GeForce GTS 8800 (rev 8.17.12.9573 2/9/2012) and having trouble with Aero on PRE, PSE and OE version 10 and a dual monitor system. The problems are numerous and involve trying to resize windows and display resolutions with these pro
-
Over active 3 year old put two discs into our 13" Mid 2009 MacBook. Hitting the eject key does nothing. Any ideas?
-
My home button does not respond sometimes
My home button on my iPhone 4 is unresponsive half the time. Help!
-
Safari 5 won't load on Windows 7
Hi, I've recently upgraded my Safari to Safari 5 and it does not load, just shows the spinning sign. I've tried uninstalling and reinstalling, placing of Apple Application Support files into Safari folder, but still no sign of improvement. Do advise,