How to get rid of repeat groups using the query? Its my sql script.
Mr President.
worm of Oracle's 10g express edition
I want to get rid of repeating groups and wants to get result like
If my table script is as below
BEGIN -- drop tables EXECUTE IMMEDIATE 'DROP TABLE CUSTOMER'; EXECUTE IMMEDIATE 'DROP TABLE PRODUCT'; EXECUTE IMMEDIATE 'DROP TABLE SUPPLIER'; EXECUTE IMMEDIATE 'DROP TABLE PURCHASE'; EXECUTE IMMEDIATE 'DROP TABLE PURCHASELINE'; EXECUTE IMMEDIATE 'DROP TABLE SALES'; EXECUTE IMMEDIATE 'DROP TABLE SALESLINE'; EXECUTE IMMEDIATE 'DROP TABLE STOCK'; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(''); END; / CREATE TABLE CUSTOMER ( cust_id NUMBER NOT NULL , name VARCHAR2(50) NOT NULL , address VARCHAR2(100) DEFAULT NULL , contactno VARCHAR2(20) DEFAULT NULL , CONSTRAINT CUSTOMER_PK PRIMARY KEY ( cust_id ) ENABLE ); CREATE TABLE PRODUCT ( prod_id NUMBER NOT NULL , name VARCHAR2(50) NOT NULL , description VARCHAR2(50) DEFAULT NULL , CONSTRAINT PRODUCT_PK PRIMARY KEY ( prod_id ) ENABLE ); CREATE TABLE SUPPLIER ( suplr_id NUMBER NOT NULL , name VARCHAR2(50) NOT NULL , address VARCHAR2(100) DEFAULT NULL , contactno VARCHAR2(20) DEFAULT NULL , CONSTRAINT SUPPLIER_PK PRIMARY KEY ( suplr_id ) ENABLE ); CREATE TABLE PURCHASE ( pur_id NUMBER NOT NULL , pur_date DATE NOT NULL , suplr_id NUMBER DEFAULT '0' , CONSTRAINT PUR_SUPLR_FK FOREIGN KEY ( suplr_id ) REFERENCES SUPPLIER ( suplr_id ) , CONSTRAINT PURCHASE_PK PRIMARY KEY ( pur_id ) ENABLE ); CREATE TABLE PURCHASELINE ( pur_id NUMBER DEFAULT '0' NOT NULL , prod_id NUMBER DEFAULT '0' NOT NULL , pur_qty NUMBER DEFAULT '0' NOT NULL , unit_pur_price NUMBER DEFAULT '0' NOT NULL , CONSTRAINT PUR_LINE_PUR_FK FOREIGN KEY ( pur_id ) REFERENCES PURCHASE ( pur_id ) , CONSTRAINT PUR_LINE_POD_FK FOREIGN KEY ( prod_id ) REFERENCES PRODUCT ( prod_id ) , CONSTRAINT PUR_LINE_PK PRIMARY KEY ( pur_id,prod_id ) ENABLE ); CREATE TABLE SALES ( sal_id NUMBER NOT NULL , sal_date DATE DEFAULT NULL , cust_id NUMBER DEFAULT '0' , CONSTRAINT PUR_CUSTR_FK FOREIGN KEY ( cust_id ) REFERENCES CUSTOMER ( cust_id ) , CONSTRAINT SALES_PK PRIMARY KEY ( sal_id ) ENABLE ); CREATE TABLE SALESLINE ( sal_id NUMBER DEFAULT '0' NOT NULL , prod_id NUMBER DEFAULT '0' NOT NULL , sal_qty NUMBER DEFAULT '0' NOT NULL , unit_sal_price NUMBER DEFAULT '0' NOT NULL , CONSTRAINT SAL_LINE_SAL_FK FOREIGN KEY ( sal_id ) REFERENCES SALES ( sal_id ) , CONSTRAINT SAL_LINE_POD_FK FOREIGN KEY ( prod_id ) REFERENCES PRODUCT ( prod_id ) , CONSTRAINT SAL_LINE_PK PRIMARY KEY ( sal_id,prod_id ) ENABLE ); CREATE TABLE STOCK ( prod_id NUMBER NOT NULL , prod_qty NUMBER DEFAULT '0' NOT NULL , re_ord_level NUMBER DEFAULT '0' NOT NULL , CONSTRAINT STOCK_POD_FK FOREIGN KEY ( prod_id ) REFERENCES PRODUCT ( prod_id ) , CONSTRAINT STOCK_PK PRIMARY KEY ( prod_id ) ENABLE ); SET DEFINE OFF; -- ***** Populate Tables ***** --CUSTOMER table data INSERT INTO CUSTOMER VALUES(1,'Kamrul Hasan','Moghbazar, Dhaka','0456789123'); INSERT INTO CUSTOMER VALUES(2,'Rabiul Alam','Motijheel, Dhaka','0567891234'); INSERT INTO CUSTOMER VALUES(3,'Shahed Hasan','2-G/1,2-2,Mirpur, Dhaka','0678912345'); --PRODUCT table data INSERT INTO PRODUCT VALUES(1,'RAM',NULL); INSERT INTO PRODUCT VALUES(2,'DVD Drive',NULL); INSERT INTO PRODUCT VALUES(3,'HDD','160 GB Satta'); INSERT INTO PRODUCT VALUES(4,'Monitor','LCD 19\"'); INSERT INTO PRODUCT VALUES(5,'Printer','HP Color'); INSERT INTO PRODUCT VALUES(6,'Keyboard','Multimedia Keyborad (Customised)'); INSERT INTO PRODUCT VALUES(7,'Mouse','Customised Mouse'); -- SUPPLIER table data INSERT INTO SUPPLIER VALUES(1,'Salam Enterprise','2-H/1-10, Mirpur, Dhaka, Bangladesh','0123456789'); INSERT INTO SUPPLIER VALUES(2,'ABC Supplies','Dhanmondi, Dhaka','0234567891'); INSERT INTO SUPPLIER VALUES(3,'XYZ Company','52 Gabtali, Dhaka','0345678912'); --PURCHASE table data INSERT INTO PURCHASE VALUES(1,TO_DATE('12-12-2007','dd-mm-yyyy'),1); INSERT INTO PURCHASE VALUES(2,TO_DATE('13-12-2007','dd-mm-yyyy'),2); INSERT INTO PURCHASE VALUES(3,TO_DATE('13-12-2007','dd-mm-yyyy'),1); INSERT INTO PURCHASE VALUES(4,TO_DATE('14-12-2007','dd-mm-yyyy'),1); INSERT INTO PURCHASE VALUES(5,TO_DATE('15-12-2007','dd-mm-yyyy'),2); INSERT INTO PURCHASE VALUES(6,TO_DATE('20-12-2007','dd-mm-yyyy'),3); INSERT INTO PURCHASE VALUES(7,TO_DATE('05-01-2007','dd-mm-yyyy'),2); INSERT INTO PURCHASE VALUES(8,TO_DATE('06-05-2007','dd-mm-yyyy'),3); INSERT INTO PURCHASE VALUES(9,TO_DATE('15-07-2008','dd-mm-yyyy'),1); --PURCHASELINE table data INSERT INTO PURCHASELINE VALUES(1,1,25,900); INSERT INTO PURCHASELINE VALUES(1,2,10,1700); INSERT INTO PURCHASELINE VALUES(1,3,10,5000); INSERT INTO PURCHASELINE VALUES(1,4,9,5500); INSERT INTO PURCHASELINE VALUES(1,7,100,250); INSERT INTO PURCHASELINE VALUES(2,3,15,5000); INSERT INTO PURCHASELINE VALUES(2,6,20,500); INSERT INTO PURCHASELINE VALUES(3,6,25,450); INSERT INTO PURCHASELINE VALUES(4,7,100,200); INSERT INTO PURCHASELINE VALUES(5,5,10,3450); INSERT INTO PURCHASELINE VALUES(5,6,10,180); INSERT INTO PURCHASELINE VALUES(6,1,15,900); --SALES table data INSERT INTO SALES VALUES(1,TO_DATE('12-12-2007','dd-mm-yyyy'),2); INSERT INTO SALES VALUES(2,TO_DATE('15-12-2007','dd-mm-yyyy'),3); INSERT INTO SALES VALUES(3,TO_DATE('20-12-2007','dd-mm-yyyy'),2); INSERT INTO SALES VALUES(4,TO_DATE('28-12-2007','dd-mm-yyyy'),3); INSERT INTO SALES VALUES(5,TO_DATE('05-01-2008','dd-mm-yyyy'),1); INSERT INTO SALES VALUES(6,TO_DATE('12-01-2008','dd-mm-yyyy'),3); INSERT INTO SALES VALUES(7,TO_DATE('12-02-2008','dd-mm-yyyy'),1); INSERT INTO SALES VALUES(8,TO_DATE('12-02-2008','dd-mm-yyyy'),2); INSERT INTO SALES VALUES(9,TO_DATE('12-02-2008','dd-mm-yyyy'),3); --SALESLINE table data INSERT INTO SALESLINE VALUES(1,1,3,1000); INSERT INTO SALESLINE VALUES(1,3,1,5500); INSERT INTO SALESLINE VALUES(1,4,1,6000); INSERT INTO SALESLINE VALUES(1,6,2,500); INSERT INTO SALESLINE VALUES(1,7,2,200); INSERT INTO SALESLINE VALUES(2,2,2,1900); INSERT INTO SALESLINE VALUES(2,7,2,200); INSERT INTO SALESLINE VALUES(3,4,1,5500); INSERT INTO SALESLINE VALUES(4,2,1,2200); INSERT INTO SALESLINE VALUES(5,6,1,300); INSERT INTO SALESLINE VALUES(5,7,2,250); INSERT INTO SALESLINE VALUES(6,6,1,300); INSERT INTO SALESLINE VALUES(6,7,3,180); INSERT INTO SALESLINE VALUES(7,1,2,1000); INSERT INTO SALESLINE VALUES(7,2,1,1900); INSERT INTO SALESLINE VALUES(7,3,2,5500); INSERT INTO SALESLINE VALUES(8,4,1,5500); INSERT INTO SALESLINE VALUES(8,6,2,300); INSERT INTO SALESLINE VALUES(8,7,1,200); INSERT INTO SALESLINE VALUES(9,1,3,1000); INSERT INTO SALESLINE VALUES(9,3,2,5500); INSERT INTO SALESLINE VALUES(9,5,2,1000); --STOCK table data INSERT INTO STOCK VALUES(1,200,15); INSERT INTO STOCK VALUES(2,25,10); INSERT INTO STOCK VALUES(3,40,10); INSERT INTO STOCK VALUES(4,20,10); INSERT INTO STOCK VALUES(5,10,10); INSERT INTO STOCK VALUES(6,50,20); INSERT INTO STOCK VALUES(7,150,20); COMMIT;
Concerning
I could not figure out how you pulled your expected results, especially the last column. I guess that your problem I have several prod_id table productline / salesline. If a group of prod_id in these table should solve your problem. Something like that
SQL> select p.prod_id as product_prod_id 2 , p.name as product_name 3 , p.description as product_description 4 , s.prod_qty as stock_prod_qty 5 , s.re_ord_level as stock_re_ord_level 6 , pl.pur_qty as purchaseline_pur_qty 7 , pl.unit_pur_price as purchaseline_unit_pur_price 8 , sl.sal_qty as salesline_sal_qty 9 , sl.unit_sal_price as salesline_unit_sal_price 10 from product p 11 join stock s 12 on p.prod_id = s.prod_id 13 join ( 14 select prod_id 15 , sum(pur_qty) pur_qty 16 , sum(unit_pur_price) unit_pur_price 17 from purchaseline 18 group 19 by prod_id 20 ) pl 21 on p.prod_id = pl.prod_id 22 join ( 23 select prod_id 24 , sum(sal_qty) sal_qty 25 , sum(unit_sal_price) unit_sal_price 26 from salesline 27 group 28 by prod_id 29 ) sl 30 on p.prod_id = sl.prod_id 31 order 32 by p.prod_id; PRODUCT_PROD_ID PRODUCT_NAME PRODUCT_DESCRIPTION STOCK_PROD_QTY STOCK_RE_ORD_LEVEL PURCHASELINE_PUR_QTY PURCHASELINE_UNIT_PUR_PRICE SALESLINE_SAL_QTY SALESLINE_UNIT_SAL_PRICE --------------- -------------------- ---------------------------------------- -------------- ------------------ -------------------- --------------------------- ----------------- ------------------------ 1 RAM 200 15 40 1800 8 3000 2 DVD Drive 25 10 10 1700 4 6000 3 HDD 160 GB Satta 40 10 25 10000 5 16500 4 Monitor LCD 19\" 20 10 9 5500 3 17000 5 Printer HP Color 10 10 10 3450 2 1000 6 Keyboard Multimedia Keyborad (Customised) 50 20 55 1130 6 1400 7 Mouse Customised Mouse 150 20 200 450 10 1030 7 rows selected.
Tags: Database
Similar Questions
-
DROID: How to get rid of several icons on the homepage email?
I have two icons of mail on my homepage and wants to get rid of one of them. I only email service so that they are pointing to the same service. Anyone know how to get rid of these?
You can remove icons on your homescreen by long pressing the icon until you feel a mood and then by dragging the icon to the trash (when the menu tab is usually, the icon turns red when sound over the trash).
I hope this helps!
-
How to get rid of out-of-use devices of ADE so I can allow my new camera?
My A.D.E will be n ot allow my new Kobo e-reader. When I try it says that there are already too many permissions. How can I get rid of the (unauthorise) out-of-use devices, that is to say my previous two and now obsolete kobo e-readers of ADE, so I can allow my new camera?
You need to speak with the service from Adobe.
It will delete ALL your records, and you must reregister those you want.
For some reason, Adobe isn't any sensible system online to view/edit the records.
http://www.Adobe.com/support/digitaleditions/supportinfo/
and open a cat.
FAQ information to
http://www.Adobe.com/UK/products/Digital-Editions/FAQ.html
See "What is the maximum number of computers and devices that I can activate?"
who sends you
http://helpx.Adobe.com/digital-editions.html
that gets you finally ('contact support' to)
-
I have a grid of cube on top of my document with a cube icon in the upper left corner, I can't access. How can I get rid of these?
With the help of the new CC Illustrator
Thank you.
Command shift I - Mac
Shift Ctrl I - Win
-
random hash lines will appear on the tabs and continue through each open tab when... How can I get rid of this whit out down gradeing to an earlier version?
COR - el said
You can try to disable hardware acceleration in Firefox.
- Tools > Options > advanced > General > Browsing: "use hardware acceleration when available.
You will need to close and restart Firefox after enabling/disabling this setting.
Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem.
- Put yourself in the DEFAULT theme: Firefox/tools > Modules > appearance
- Do NOT click on the reset button on the startup window Mode safe
-
How to get rid of a shadow on the skin?
How can I get rid of a really dark and sensitive shade that sits on the skin in a photo.
To illustrate the great Silkrooster instructions:
(1) create a new layer above the photo you want to correct by clicking on the new layer button highlighted below.
(2) use the Paint Bucket tool, fill the new layer with 50% gray.
(3) in the Layers panel, change the blending mode of the grey layer to screen.
(4) create a new mask to the gray layer holding the alt/option key down while clicking on the button below.
(5) make sure the mask (the black rectangle in the layers panel) is selected. Select the white color and a brush with edges rounded and paint on the hard shadows to clarify them. As Silkrooster said before, you can also play with the opacity of the brush and black paint will cancel the lightning that you did. It will take a few tries.
Here are before and after shots of an area, I worked on. You can see that the shadow under my eye is not as hard as it was in the original.
Silkrooster thanks for your great answer, and I hope you find this useful Jeanne!
-
How to get rid of a spot on the Panel rear aluminum macbook pro?
I have a macbook pro covered by a pink hard case. After that I removed the case, there is a spot on the rear panel in aluminium. How can I get rid of him?
Post edited by: SweetSilence
Have you contacted the manufacturer of the case?
This is the Office Mac Pro forum. I asked that your post be moved to the MacBook Pro laptop forum.
-
How to get rid of a book in the cloud?
I have an ibook appearing in my 'cloud' and I want to get rid of it PERMANENTLY.
Any idea? Thank you
You can hide (you can't permanently remove any element of your purchase history) on the cloud via iTunes on your computer (if iBooks app you use a Mac): mask and unmask purchases iTunes or iBooks on your Mac or PC - Apple Support
-
How to get rid of icon rotation for the updating of the region?
Hello
I Timer Plugin of Patrick where I refresh a report every 5 seconds. How can I get rid of the spinning refresh icon?
Thanks, Jürgen
u treatment {display: none ;}}
-
How to get rid of white space above the footer of Muse
I have a Web site that has several random pages where different sizes of white space will appear above the footer, even if I did not put them there. How can I get rid of that empty white space?
It's the page in Preview Mode:
This is the page of Design Mode:
It's the master page in Design Mode:
It's the Site properties:
Hello
As I see you make reference to a white space is as shown below, am I right?
Could you please access this page in project muse and "select all items on a page" and check if there is any rectangle or div at the bottom? If Yes! try to delete the same and re - publish the site and check if that helps.
Forward to your response.
PS: Please uncheck the sticky footer option in the Site properties and check if it works.
-
How to get a serial number after using the trial?
I downloaded the demo of Lightroom 4, and I liked it, so I'll buy it. However, when I click on the button 'buy' on the Launcher, it redirects me to the purchase page and he asks me if I want to download or have a disk shipped to me. I just want to buy a serial number to activate my copy for good, since I the trial is essentially the version complete but with a time limit. How can I do this?
Click on download. you don't have to install (or even save the download). Simply use the serial number to activate the trial you already installed.
remove the unnecessary download.
-
How to get rid of box information on the Zoom tool, marquee and cultures?
Thank you!
-
How to get a new column without using the update (Please check with the requirment)
write a query to display the current sal and the new sal for all employees
condition
If job = 'MANAGER' and deptno in (10.20) and then newsal has increased by 15% to the current salary.
If work! = 'MANAGER' and deptno in (10.20) and then newsal has increased by 25% to the current salary.Select ename, sal as old_sal,
-CASE when work = 'MANAGER' and deptno in (10,20) then (sal + (sal * 15) / 100)
When job! = 'MANAGER' and deptno in (10.20) and then (sal + (sal * 25) / 100)
Another Sal
END as new_sal
EMP; -
Does anyone know how to get rid of the calendar in the window Live on XP? I do not use it, and whenever I check my e-mail, it checks the calendar, slows things down to the top.
Thank you!Debnfurkidsoriginal title: get rid of the calendar in live mailHi Debnfurkids,
I recommend you post your query in Live Mail Forums for assistance on this issue.
-
I posted a question about the FBI virus. How to get rid of him. I ' v was only one answer. Someone to give here can help me with that. I'm 62, and I'm not a computer genius. I have some [eratly helpgetting need to get rid of the virus of the FBI. MS antivirus and scan not work or identify it. Help, please! 1
Emisoft is a desperately slow download, as I just discovered.
You can simply run Malwarebytes and it...
http://www.Microsoft.com/security/scanner/en-us/default.aspx
Maybe you are looking for
-
Need drivers of Windows XP Home for Satellite M200
Dear technicians, I recently formatted my Satellite and installed with XP (Vista, originally). I managed to get most of the pilots but trouble with the USB ports and the function keys. Could someone good to help me where can I get this driver. I trie
-
CTRL Alt Del does not work Windows 2015 10 rMBP
Hi all I have a MacBook Pro for Windows 10 15 "Bootcamped retina. CTRL Alt Del does not, any more than the function keys (brightness, mute, etc.). I tried to manually reinstall the keyboard driver. It installs ok but does not solve the problem. On Re
-
Cannot print - error activates directory
Original title: printer print print Cannot print; Get the message "Active Directory Domain Services not available
-
Save yourself some headaches if your RAID with Intel RST race of 10 to win... Installed Intel Rapid Storage Technology 15.2.0.1020 technology application & driver. Readers SanDisk Extreme Pro 240 GB SanDisk SSD Dashboard 1.4.3 lost to see and choose
-
I just bought a key for windows 10 and I have windows 7 How can I download windows 10 with my key. What I need to first install windows 10 trail?