 |
|
 |
|
Next: Validate if data exists
|
| Author |
Message |
External

Since: Dec 02, 2008 Posts: 3
|
(Msg. 1) Posted: Tue Dec 02, 2008 1:25 pm
Post subject: Oracle query needed Archived from groups: alt>php>sql (more info?)
|
|
|
Hi,
I have difficulty creating a query, perhaps you can help me...
I have an Oracle database with the following columns in a table:
franchiser, store, cashregister, receiptdate
Now I want to select the first receiptdate for every unique cashregister.
Can you tell me what query does this ? >> Stay informed about: Oracle query needed |
|
| Back to top |
|
 |  |
External

Since: Nov 02, 2008 Posts: 17
|
(Msg. 2) Posted: Tue Dec 02, 2008 3:25 pm
Post subject: Re: Oracle query needed [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Dutchie schreef:
> Hi,
>
> I have difficulty creating a query, perhaps you can help me...
>
> I have an Oracle database with the following columns in a table:
>
> franchiser, store, cashregister, receiptdate
>
> Now I want to select the first receiptdate for every unique cashregister.
> Can you tell me what query does this ?
>
>
you want things for every unique cashregister, so you need to use the
'GROUP BY cashregister'
and you need the 1st (or the smallest) receiptdate. This can be done
with 'MIN(receiptdate)'
so your query is something like:
SELECT MIN(receiptdate), cashregister FROM table GROUP BY cashregister;
but, its not a difficult query, so i'm not sue if this is right....  >> Stay informed about: Oracle query needed |
|
| Back to top |
|
 |  |
External

Since: Dec 02, 2008 Posts: 3
|
(Msg. 3) Posted: Tue Dec 02, 2008 3:25 pm
Post subject: Re: Oracle query needed [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Luuk wrote:
> Dutchie schreef:
>> Hi,
>>
>> I have difficulty creating a query, perhaps you can help me...
>>
>> I have an Oracle database with the following columns in a table:
>>
>> franchiser, store, cashregister, receiptdate
>>
>> Now I want to select the first receiptdate for every unique cashregister.
>> Can you tell me what query does this ?
>>
>>
>
> you want things for every unique cashregister, so you need to use the
> 'GROUP BY cashregister'
>
> and you need the 1st (or the smallest) receiptdate. This can be done
> with 'MIN(receiptdate)'
>
> so your query is something like:
> SELECT MIN(receiptdate), cashregister FROM table GROUP BY cashregister;
>
> but, its not a difficult query, so i'm not sue if this is right....
hi, and thanks
the cashregister value is not unique
below is some sample data, hope you can find a query for this.
i'm still practicing with sql, but could not tackle this one yet
(therefore i have a read-only account  )
franchiser, store, cashregister, receiptdate
1, 1, 1, YYYY-MM-DD HH:MM:SS
1, 2, 1, YYYY-MM-DD HH:MM:SS
1, 2, 2, YYYY-MM-DD HH:MM:SS
1, 3, 1, YYYY-MM-DD HH:MM:SS
2, 1, 1, YYYY-MM-DD HH:MM:SS
3, 1, 1, YYYY-MM-DD HH:MM:SS
3, 1, 2, YYYY-MM-DD HH:MM:SS
etc... >> Stay informed about: Oracle query needed |
|
| Back to top |
|
 |  |
External

Since: Nov 02, 2008 Posts: 17
|
(Msg. 4) Posted: Tue Dec 02, 2008 4:25 pm
Post subject: Re: Oracle query needed [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Dutchie schreef:
> Luuk wrote:
>> Dutchie schreef:
>>> Hi,
>>>
>>> I have difficulty creating a query, perhaps you can help me...
>>>
>>> I have an Oracle database with the following columns in a table:
>>>
>>> franchiser, store, cashregister, receiptdate
>>>
>>> Now I want to select the first receiptdate for every unique
>>> cashregister.
>>> Can you tell me what query does this ?
>>>
>>>
>>
>> you want things for every unique cashregister, so you need to use the
>> 'GROUP BY cashregister'
>>
>> and you need the 1st (or the smallest) receiptdate. This can be done
>> with 'MIN(receiptdate)'
>>
>> so your query is something like:
>> SELECT MIN(receiptdate), cashregister FROM table GROUP BY cashregister;
>>
>> but, its not a difficult query, so i'm not sue if this is right....
>
> hi, and thanks
> the cashregister value is not unique
> below is some sample data, hope you can find a query for this.
> i'm still practicing with sql, but could not tackle this one yet
> (therefore i have a read-only account )
>
> franchiser, store, cashregister, receiptdate
> 1, 1, 1, YYYY-MM-DD HH:MM:SS
> 1, 2, 1, YYYY-MM-DD HH:MM:SS
> 1, 2, 2, YYYY-MM-DD HH:MM:SS
> 1, 3, 1, YYYY-MM-DD HH:MM:SS
> 2, 1, 1, YYYY-MM-DD HH:MM:SS
> 3, 1, 1, YYYY-MM-DD HH:MM:SS
> 3, 1, 2, YYYY-MM-DD HH:MM:SS
> etc...
so, did you at least TRY my query ?
with this sample data it should give:
YYYY-MM-DD, 1
YYYY-MM-DD, 2 >> Stay informed about: Oracle query needed |
|
| Back to top |
|
 |  |
External

Since: Dec 02, 2008 Posts: 3
|
(Msg. 5) Posted: Tue Dec 02, 2008 6:25 pm
Post subject: Re: Oracle query needed [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Luuk wrote:
> Dutchie schreef:
>> Luuk wrote:
>>> Dutchie schreef:
>>>> Hi,
>>>>
>>>> I have difficulty creating a query, perhaps you can help me...
>>>>
>>>> I have an Oracle database with the following columns in a table:
>>>>
>>>> franchiser, store, cashregister, receiptdate
>>>>
>>>> Now I want to select the first receiptdate for every unique
>>>> cashregister.
>>>> Can you tell me what query does this ?
>>>>
>>>>
>>>
>>> you want things for every unique cashregister, so you need to use the
>>> 'GROUP BY cashregister'
>>>
>>> and you need the 1st (or the smallest) receiptdate. This can be done
>>> with 'MIN(receiptdate)'
>>>
>>> so your query is something like:
>>> SELECT MIN(receiptdate), cashregister FROM table GROUP BY cashregister;
>>>
>>> but, its not a difficult query, so i'm not sue if this is right....
>>
>> hi, and thanks
>> the cashregister value is not unique
>> below is some sample data, hope you can find a query for this.
>> i'm still practicing with sql, but could not tackle this one yet
>> (therefore i have a read-only account )
>>
>> franchiser, store, cashregister, receiptdate
>> 1, 1, 1, YYYY-MM-DD HH:MM:SS
>> 1, 2, 1, YYYY-MM-DD HH:MM:SS
>> 1, 2, 2, YYYY-MM-DD HH:MM:SS
>> 1, 3, 1, YYYY-MM-DD HH:MM:SS
>> 2, 1, 1, YYYY-MM-DD HH:MM:SS
>> 3, 1, 1, YYYY-MM-DD HH:MM:SS
>> 3, 1, 2, YYYY-MM-DD HH:MM:SS
>> etc...
>
> so, did you at least TRY my query ?
>
> with this sample data it should give:
> YYYY-MM-DD, 1
> YYYY-MM-DD, 2
Actually the database was inaccessible due to a backup
But hey, I changed the query to:
SELECT MIN(receiptdate), franchiser, store, cashregister FROM table
GROUP BY franchiser, store, cashregister;
and it works.
That easy !
I thought it would simply select all combinations of
franchiser-store-cashregister and then only show the one record that
was the oldest of that set.
But I am misunderstood the MIN() function
Thanks for the help ! >> Stay informed about: Oracle query needed |
|
| Back to top |
|
 |  |
| Related Topics: | Warning help needed - clueless - Hello I have been moderating a phpweblog website (www.sfdrcm.com) but am clueless about the programming. In the last few days the following warning had appeared before each news article Warning: mysql_result(): supplied argument is not a valid MySQL..
How can i Optimize sql Query ? - Hi, I'd like to optimize this query: Code: SELECT * FROM `links` WHERE active = "1" AND mainweight != 0 ORDER BY Rand()*(1/mainweight) LIMIT 5 I have a database of links wich has 3 000 rows. I'd like to select weighted random links from ...
combobox and print query - Hi, I have problem with php and MSSQL I have a combobox with the name of 10 company and in my database i have 1 table different for each company. I need that when the user choose in the combobox one of this company appeard the table with the data. ...
Mysql query cache? - Hello. I have a strange problem with my website at work. There is a database with some product data. Data is registered thru php - website, and once a week a raport is generated from this data. If a mistake was made, the data of current week can be..
function problem involving query - I'm trying to construct a database of old houses including the parts they are made of as roof construction, floor construction, types of windows, vaults, etc. To do that I set up several tables. One containing the house id, address, last visit, etc. For.... |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|