Re: Query help

From: Hui Xie <hui(dot)xie(at)axisoft(dot)com(dot)hk>
To: novice <user(dot)postgresql(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-general-owner(at)postgresql(dot)org
Subject: Re: Query help
Date: 2008-08-15 01:51:45
Message-ID: OFB1CBE105.276EC3F1-ON482574A6.0009C69A-482574A6.0009D319@as03.axiscan.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi ,

below can work?
select config_id, start_day as day, start_time, end_time from config
union
select config_id, end_day as day, start_time, end_time from config

Best Regards,
Hui Xie
-------------------------------------------
Axisoft Co. Ltd. Zhuhai Branch
Tel: (86) 0756-3612121 8858

novice <user(dot)postgresql(at)gmail(dot)com>
Sent by: pgsql-general-owner(at)postgresql(dot)org
15/08/2008 08:32 AM

To
pgsql-general(at)postgresql(dot)org
cc

Subject
[GENERAL] Query help

Hi,
I have a table

select id, config_id, start_day, end_day, start_time, end_time from
config;

id | config_id | start_day | end_day | start_time | end_time
-----+-----------+-----------+---------+------------+----------
1 | 101 | Mon | Sun | 08:30:00 | 18:00:00
2 | 101 | Mon | Sun | 18:00:00 | 22:00:00
3 | 555 | Mon | Fri | 08:30:00 | 16:00:00

I'd like to write a query to generate the following... is it possible at
all?

config_id | day | start_time | end_time
-----------+-----------+---------+-------------
101 | Mon | 08:30:00 | 18:00:00
101 | Mon | 18:00:00 | 22:00:00
101 | Tue | 08:30:00 | 18:00:00
101 | Tue | 18:00:00 | 22:00:00
101 | Wed | 08:30:00 | 18:00:00
101 | Wed | 18:00:00 | 22:00:00
101 | Thu | 08:30:00 | 18:00:00
101 | Thu | 18:00:00 | 22:00:00
101 | Fri | 08:30:00 | 18:00:00
101 | Fri | 18:00:00 | 22:00:00
101 | Sat | 08:30:00 | 18:00:00
101 | Sat | 18:00:00 | 22:00:00
101 | Sun | 08:30:00 | 18:00:00
101 | Sun | 18:00:00 | 22:00:00
555 | Mon | 08:30:00 | 18:00:00
555 | Tue | 08:30:00 | 18:00:00
555 | Wed | 08:30:00 | 18:00:00
555 | Thu | 08:30:00 | 18:00:00
555 | Fri | 08:30:00 | 18:00:00

Thanks

--
Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

*** The email has been scanned by AxiScan ***

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-08-15 01:58:57 Re: Custom sort
Previous Message Dale Harris 2008-08-15 00:34:10 Re: cannot use result of (insert .. returning)