473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

job for sql, pl/pgsql,gawk,perl or ??

Dear all,

I have this problem with getting information out of my
database and I don't know if it is my knowledge of sql
or that this is something that can't be done in sql.

I have the following table:

id fdate prod price stat nr_items sdate
x1 23-11-2003 123 456 yes 7 01-11-03
x1 23-11-2003 123 456 may 4 07-11-03
x1 23-11-2003 123 400 yes 7 14-11-03
x2 29-11-2003 201 711 no 6 01-11-03
x2 29-11-2003 133 700 no 6 08-11-03

Here, you can see that id x1 is interested in product
123 that we offer for 456 euro's and that he's sure
and wants 7 items. Then almost 6 days afterwards he
mails us to change his order to 4 items and after we
arrange a price reduction.

For various reasons I sometimes want only these
customers and reason as follows:
"Give me the id's of persons wo start with a
status="yes" and end with a status="yes". Then I can
track so called "doubters".

How to do this in postgresql?
So basically I want to be able to scan a file, order
it by id,sdate and the want to look at the field stat.
If I see that the contents of the field changes from
yes to something else and then back to yes, I select
the id. Other positives would be stat started from no
and ending in yes.

The total number of changes an id can have varies.

Can this be done in sql? Or is this a pl/pgsql task?
In that case, what should I think of? Another option
for me is to output a textfile and try to do it in
gawk or perl or something else.


__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
1 1134

On Aug 28, 2004, at 4:20 AM, Dino Vliet wrote:
For various reasons I sometimes want only these
customers and reason as follows:
"Give me the id's of persons wo start with a
status="yes" and end with a status="yes". Then I can
track so called "doubters".

How to do this in postgresql?


If I understand your table schema correctly, you're going to want to do
a couple of self-joins on the table (which I shall call "foo"),
something like:

select id
from foo as foo1
join foo as foo2 using (id, prod, fdate)
join foo as foo3 using (id, prod, fdate)
where
foo1.stat = 'yes'
and foo2.stat <> 'yes'
and foo3.stat = 'yes'
and foo2.sdate > foo1.sdate
and foo3.sdate > foo2.sdate;

Something link this will probably work for the yes -> not yes -> yes
situations. However, I think you may also get what you're looking for
with anything that goes from not 'yes' to 'yes'. This covers both the
situation of changing from 'yes' to not 'yes' and back to 'yes' as well
as the case from 'no' to 'yes'.

select id
from foo as foo1
join foo as foo2 using (id, prod, fdate)
where
foo1.stat <> 'yes'
and foo2.stat = 'yes'
and foo2.sdate > foo1.sdate;

Just so you know, this isn't a PostgreSQL-specific issue, but rather an
SQL one. You might want to check out some SQL tutorials on the web or
perhaps pick up a book or two on SQL. I've found Joe Celko's "SQL for
Smarties" helpful.

Good luck!

Michael Glaesemann
grzm myrealbox com
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hema Sekhar | last post by:
Hi I am Hemasekhar K.P I am trying to replicae pgsql on REDHATLinux 8, but the site http://gborg.postgresql.org/genpage?replication_72install. is giving instructions on REDHATLinux 7, is there...
15
by: Birahim FALL | last post by:
Hi, I'm very fresh to PostgreSQL, coming from Oracle. I want to developp web applications based on apache and postgresql. Is there an equivalent of OWA server (Oracle Web Application server) for...
4
by: Rajesh Kumar Mallah | last post by:
Hi, We need to implement following logic efficiently. SELECT * from some_table where .... IF rows_matched = 1 THEN use the single row that matched.
34
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my...
4
by: Postgresql | last post by:
Hello, I am unable to get on many of the postgresql mailing lists. I usually get this message back with no attachment and no email comes afterwards with a confirmation. I've tried this over and...
7
by: snpe | last post by:
Is it down ? regards ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's...
1
by: John French | last post by:
I just installed postgresql 7.4.5 and pgadmin3 1.0.2 on FreeBSD and noticed that pgadmin allows the pgsql user to log in while ignoring the password. You can enter a wrong password or no password...
1
by: sysxperts | last post by:
Hello, Having an issue that is specific to PHP compiled with PGSQL support with versions noted in subject line. I understand that there are many variables to consider here but believe I have...
2
cassbiz
by: cassbiz | last post by:
Our old machine was hacked and I need to remove a line from just about every *.htm*, *.php, *.cgi, etc... file the lines that I need to remove are I have read up on gawk but most of the stuff I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.