I have 3 tables (Items, ItemProperties and ItemPropertyKeys). ItemPropertyKeys contains of property keys like title, quantity, author for the items and ItemProperties contains the actual property (the name of the author, the title of the item etc.) There could be more than one property refering to one key for a single item (for example the item could have more than one names).
Example:
Item SomeSong
ItemPropertyKey title
ItemProperty #1 with key title -> "Lalala"
ItemProperty #2 with key title -> "Bla bla bla"
Wanted Result:
Item Key Title
SomeSong title "Lalala"(or "Bla bla bla")
Received Result so far
Item Key Title
SomeSong title "Lalala"
SomeSong title "Bla bla bla"
I need to select items (for example by date range) and theirs titles but if an item has more than one title I need to select only one of them.
I've tried everything so far and had no luck. And also I shouldn't use stored procedures.
Hope I've been clear enough.
Help will be appreciated.
Thanks in advance.
13 1553
Could you please post your source code that you have tried do far?
-
-
SELECT ITEMID AS "ItemId",DOWNLOADEDDATE AS "Date",ITEMTYPE AS "Type",ITEMPROPERTY AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDATE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:start AND IDO.DOWNLOADEDDATE<=:end ))GROUP BY ITEMID,DOWNLOADEDDATE,ITEMTYPE,ITEMPROPERTY ORDER BY DOWNLOADEDDATE
-
This is one of my not working scripts and here's the result:
ID Date Type Title Value
1031 2008-03-27 Melodies Hladna Nejnost 1
1031 2008-03-27 Melodies Хладна нежност 1
1040 2008-03-31 Application GGG 1
1060 2008-04-01 Melodies Hladna Nejnost 1
1060 2008-04-01 Melodies Хладна нежност 1
The items with 1031 and 1040 ids are duplicated because they have 2 titles. I need to avoid this and result should contain only one of the titles no matter which one.
Try this: -
SELECT ITEMID AS "ItemId",DOWNLOADEDDATE AS "Date",ITEMTYPE AS "Type",MAX(ITEMPROPERTY) AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDA TE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:START AND IDO.DOWNLOADEDDATE<=:END ))GROUP BY ITEMID,DOWNLOADEDDATE,ITEMTYPE ORDER BY DOWNLOADEDDATE
-
Still doesn't work
I've tried it with min too but the result was the same
-
-
SELECT ITEMID AS "ItemId",TO_DATE(DOWNLOADEDDATE) AS "Date",ITEMTYPE AS "Type",MAX(ITEMPROPERTY) AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDA TE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:START AND IDO.DOWNLOADEDDATE<=:END ))GROUP BY ITEMID,TO_DATE(DOWNLOADEDDATE),ITEMTYPE ORDER BY DOWNLOADEDDATE
-
I'm getting this:
Error starting at line 1 in command: -
-
SELECT ITEMID AS "ItemId",TO_DATE(DOWNLOADEDDATE) AS "Date",ITEMTYPE AS "Type",MAX(ITEMPROPERTY) AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM
-
( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM
-
(SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDATE FROM
-
ITEMDOWNLOADS IDO
-
JOIN ITEMS I ON I.ITEMID=IDO.ITEMID
-
JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID
-
JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title')
-
JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider'
-
JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID
-
WHERE IDO.DOWNLOADEDDATE>='2008-03-02' AND IDO.DOWNLOADEDDATE<='2008-04-03' ))
-
GROUP BY ITEMID,TO_DATE(DOWNLOADEDDATE),ITEMTYPE,ITEMPROPERTY ORDER BY DOWNLOADEDDATE
-
Error at Command Line:11 Column:71
-
Error report:
-
SQL Error: ORA-00979: not a GROUP BY expression
-
00979. 00000 - "not a GROUP BY expression"
-
*Cause:
-
*Action:
-
Just removed TO_DATE from the GROUP BY clause but it still returns duplicate results.
Just removed TO_DATE from the GROUP BY clause but it still returns duplicate results.
How is your date stored in the database? with the time stamp or only date?
In the database it's just date.
Try This: -
SELECT ITEMID AS "ItemId",DOWNLOADEDDATE AS "Date",ITEMTYPE AS "Type",ITEMPROPERTY AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,MAX(ITP.ITEMPROPERTY),DOWNLOADEDDA TE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:START AND IDO.DOWNLOADEDDATE<=:END GROUP BY ITEMID,DOWNLOADEDDATE, ITEMTYPE))GROUP BY ITEMID,DOWNLOADEDDATE,ITEMTYPE,ITEMPROPERTY ORDER BY DOWNLOADEDDATE
-
Try this query. I am guessing because I cannot test in my machine without table structures and data.
Still no change
Thanks for your time though
I would suggest you to take out the property and select only other tables in your query. then add the table for item property and join your inline view and this table externally.....Just select one row of item property for each id.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hjyn |
last post by:
Hi All, I create a form for the user to enter the information, the
form contains two table, table A and table B. I wrote a script to
prompt the user to fill all the necessary data if they miss to...
|
by: Gary Lundquest |
last post by:
It appears to me that MySQL version 4 returns an error messge when doing an
Insert that results in duplicate entries. Version 3 did NOT return an
error - it dropped the duplicate entries and ran...
|
by: Chetan Raj |
last post by:
Hi All,
One of my friend asked this question on C++
>>>
Hi,
Can u give an answer to this :
We have the .h files for standard library. Consider any class (such as
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: Mark |
last post by:
When my form goes to a new record, I have a procedure that copies the last
record added to the form's underlying table into the form. The intent is that a
series of new records may have the same...
|
by: planetthoughtful |
last post by:
Hi All,
I have a C# ASP.NET page that submits back to itself to insert details
from a form into a database table. When / if the user refreshes the
page (and gets the standard warning that POST...
|
by: Oleg Konovalov |
last post by:
Hi,
I have a Java/JavaScript GUI application where I perform a lot of long DB
operations
, which takes 5-60 secs to perform.
Sometimes user double-clicks the button or just gets impatient and...
|
by: groups |
last post by:
This is my first foray into writing a generic method and maybe I've
bitten off more than I can chew.
My intent is to have a generic method that accepts a value name and
that value will be...
|
by: Dave |
last post by:
I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.
SqlException (0x80131904)
...
|
by: nomvula |
last post by:
hi guys
i need some help to duplicate records on my form datasheet:
here's the example of my form results:
ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual
UJ...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |