Re: [SQL] Query execution based on a condition

2012-12-29 Thread msi77
Change the conditions of other 3 queries, so those shall give empty row sets depending on your value. 29.12.2012, 23:06, "JORGE MALDONADO" : > I have a query similar to the one shown below but, depending on the value of > a field, only the first SELECT statement shoud execute and the other 3 sho

Re: [SQL] strange corruption?

2012-12-27 Thread msi77
Hi, Maybe you have triggers on the target table. 27.12.2012, 18:28, "John Fabiani" : > Hi, > I have the following statement in a function. > >  UPDATE orderseq >  SET orderseq_number = (orderseq_number + 1) >  WHERE (orderseq_name='InvcNumber'); > > All it does is update a single recor

Re: [SQL] Lowest 2 items per

2012-06-02 Thread msi77
Thank you for reply, Oliver. I want that you'll pay attention to the learn exercises which can by made under PostgreSQL among few other DBMS: http://sql-ex.ru/exercises/index.php?act=learn 02.06.2012, 19:00, "Oliveiros" : > Nice resource, msi77. > > Thanx for sharing. &g

Re: [SQL] Lowest 2 items per

2012-06-02 Thread msi77
A few of approaches to solve this problem: http://sql-ex.com/help/select16.php 01.06.2012, 18:34, "Relyea, Mike" : > I need a little help putting together a query.  I have the tables listed > below and I need to return the lowest two consumables (ranked by cost > divided by yield) per printer, pe

Re: [SQL] SELECT 1st field

2012-05-14 Thread msi77
Try this create view v(id) as select * from func(5); if your function returns one column. 15.05.2012, 10:01, "Jan Bakuwel" : > Hi, > > I've spend some time checking the documentation but haven't been able to > find what I'm looking for. > I've got a function that returns a set of integers and a

Re: [SQL] Duplicate information in parent and child tables

2012-04-03 Thread msi77
Maybe this will help http://sql-ex.ru/help/select18.php 04.04.2012, 02:03, "JORGE MALDONADO" : > I have a parent table and a child table. In order to detect duplicate > information I need to consider both tables. This means that a "duplicate > record" consists of one parent record and one or mor

Re: [SQL] Re: how can I get the length of columns of a table by system tables/views

2011-09-09 Thread msi77
Why not to use information schema: select column_name, character_maximum_length from information_schema.columns where table_name ='table name' 09.09.2011, 16:53, "shuaixf" : > SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) > FROM pg_catalog.pg_attribute a > WHERE a.attrelid =

Re: [SQL] F_TABLE_NUMBER_RANGE equivalent in Postgresql

2011-08-15 Thread msi77
Are you sure that dbo.F_TABLE_NUMBER_RANGE is in SQL Server? I suppose that this is UDF written by user. 16.08.2011, 08:53, "Yuan HOng" : > Hi, > > With MS-SQL sever, there is a built-in utility function > dbo.F_TABLE_NUMBER_RANGE which generates a list of number between the > given range. For e

Re: [SQL] Calculate the ratio

2011-08-15 Thread msi77
Hi, Try this select gridyear, gwcode, sum(case when cf=1 then area else o end) as cf1, sum(case when cf=0 then area else 0 end) as cf0 from table group by gridyear, gwcode http://sql-ex.ru/help/select8.php#case 15.08.2011, 16:21, "Andreas Forø Tollefsen" : > Hi all, > > This is probably quite

Re: [SQL] Aggregates puzzle

2011-04-08 Thread msi77
Try this: select * from flood_ts F join (SELECT lid, MAX(value) AS mvalue, event_id FROM flood_ts GROUP BY lid, event_id) X on F.lid = X.lid and value = mvalue and X.event_id = F.event_id 01.04.2011, 00:15, "Mark Fenbers" : > SQL gurus, > > I have a table with 4 columns:  lid(varchar), value(flo

Re: [SQL] UNIQUE on everything except primary key

2011-02-03 Thread msi77
Do all the 10 columns make a natural key? 03.02.2011, 18:44, "gvim" : > I have a table with 11 columns and want to eliminate duplication on INSERTs. > What's the best method? The obvious solution would be to create a UNIQUE > index on everything except the primary key - 'id' - but that's a 10-co

Re: [SQL] Queyring for columns which are exist in table.

2011-01-25 Thread msi77
Why would not use information schema to checking of existence of some column in a table: select column_name from information_schema.columns where table_name='tbl' -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpr

Re: [SQL] Getting top 2 by Category

2011-01-11 Thread msi77
There some ways to do this in one query. Look here: http://www.sql-ex.ru/help/select16.php --- 11.01.11, 22:00, "Ozer, Pam" :> This is probably very simple but I am drawing a blank.  Do I need to create a cursor to iterate through a table to grab the top 2 magazines per category?  He

Re: [SQL] is there a distinct function for comma lists ?

2010-09-28 Thread msi77
Hi, > And as bonus ... is there a way to find IDs that are in the list but not > in the table without creating a temporary table and use a join? Does below satisfy you? select * from (values (1), (2), (3), (5), (7), (11), (3), (6), (13), (13), (3), (11)) as X(a) where a not in(select id from m

Re: [SQL] Duplicate rows

2010-08-10 Thread msi77
A few ways to do this: http://www.sql-ex.ru/help/select17.php > Is there any way to remove a duplicate row from a table? Not my db but I have > to work with it. On version 7.4 right now. > Edward W. Rouse > Comsquared System, Inc. > 770-734-5301 > -- Sent via pgsql-sql mailing list (pgsql-sql

Re: [SQL] Multiple subquery with insert into command ?

2010-06-07 Thread msi77
Use the following: INSERT INTO umzintersect (intersection,umz00_id,pop, comm_id, name_asci) SELECT intersection(umz_project.the_geom, lau2.the_geom), umz_project.umz00_id, umz_project.pop, lau2.comm_id, lau2.name_asci FROM umz_project, lau2,big_umz WHERE umz_project.umz00_id = big_umz.umz00_i

Re: [SQL] inner join and limit

2010-06-06 Thread msi77
Hi, Some ways to do that: http://www.sql-ex.ru/help/select16.php > Hi list, > I have two table that are so represented: > t1: > id int primary key > ... other > t2: > id int primary key > t1id int fk(t1.id) > somedate date > ... other > data t1: > 1 | abcde > 2 | fghi > data t2: > 1 | 1 | 2010-05-

Re: [SQL] Howto get a group_number like row_number for groups

2010-04-12 Thread msi77
Hi, dense_rank() over (order by object) % 2 > Hi > I'd like to have an alternating colorindex in the output of a query that > consecutive rows that are the same within a colum the same number. > The query generates a readable output from a log-table and a few others > that hold referenc

Re: [SQL] "left join" not working?

2010-02-12 Thread msi77
> where p.id_line=1 this filters rows after join was applied. Try this select c.id_currency,max(p.modified_on) from currency c left join price_line p using (id_currency) where (p.id_line=1 or p.id_line is null) group by c.id_currency; > Hi, > This query: > select c.id_currency,max(p.modif

Re: [SQL] please help me on regular expression

2010-02-03 Thread msi77
Why not to use select subjectid, height from tsakai.pheno where height like '%.%'; ? > Hi everybody, > I need a bit of help on postgres reqular expression. > With a table of the following definition: > Table "tsakai.pheno" > Column | Type | Modifiers > ---+---+

Re: [SQL] combine SQL SELECT statements into one

2010-02-01 Thread msi77
Hi, SELECT (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-02-01') as count1, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-20') as count2, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-01') as count3 Serge > Good Evenin

Re: [SQL] combine SQL SELECT statements into one

2010-02-01 Thread msi77
Hi, SELECT (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-02-01') as count1, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-20') as count2, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-01') as count3 Serge > Good Evenin

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread msi77
Hi, I think you need CS collation and UNIQUE(name). > Hi, > is there a way to define a unique restraint on UPPER (textfield)? > E.g. > mytable ( > name_id serial PRIMARY KEY, > name varchar(255), > UNIQUE ( upper (name) ) > ) > psql throws a syntax error because of the upper() function.

Re: [SQL] how to do this query

2010-01-09 Thread msi77
lds short name containts > "schol1", schols_selects containts "schol1:schol2:schol3" so > schols_seleced like '%' || short_name || '%' doesn't make sense to me > since the like operator is trying to find text1 in text two with %% > right? &g

Re: [SQL] how to do this query

2010-01-09 Thread msi77
How about schols_selected like '%' || short_name || '%' > I have two tables: > students > stu_name > schols_selected > scholarships > schol_name > short_name > schols_selected is made up of scholarships the students have selected, > the field content will look like schol1:schol2:schol3

Re: [SQL] short-cutting if sum()>constant

2009-12-22 Thread msi77
> Sorry, but i don't know how a CTE can help in this case, can you explain I mean RECURSIVE CTE. You can check your condition on each iteration and stop execution when condition is false. Sergey > msi77 wrote: > > Развернуть > > Does PG support CTE? > Since 8.4 ye

Re: [SQL] short-cutting if sum()>constant

2009-12-22 Thread msi77
Does PG support CTE? You can try it. > In response to Ivan Sergio Borgonovo : > > Развернуть > > Hi, > > > > I'd like to know if > > > > select sum(qty) from t where status=37; > > > > is > constant. > > > > qty is always >0. > > > > Is there a way to skip examining further rows and return a

Re: [SQL] 8.4.1 distinct query WITHOUT order by

2009-12-21 Thread msi77
> What are the ramifications of renaming the table (containing 8000 > rows) and creating a view of the same name? View does not admit ORDER BY clause, at least, Standard does not. Sergey -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://

Re: [SQL] How to get the previous date?

2009-10-14 Thread msi77
Try this: select cast(mydate as date) -1 > Hi, > I'm using Enterprise DB PostgresPlus version 8.3. > Is there is a simple function or command like previous_date(mydate) which > when passed a particular date, simply returns the previous date? I tried > mydate - 1 > but this doesnt work. > Th