ansi-sql

List of differences between SQL databases

匆匆过客 提交于 2019-12-20 11:03:44
问题 Most SQL databases follow the ANSI SQL standards to a degree, but The standard is ambiguous, leaving some areas open to interpretation (eg: how different operations with NULLs should be handled is ambiguous) Some vendors contradict the standard outright or just lack functionality defined by the standard (eg: MySQL has a list of differences between the standard and their implementation) Some databases will behave differently depending on how they are configured, but configuration can be

ANSI SQL version of SELECT TOP 1

 ̄綄美尐妖づ 提交于 2019-12-18 19:06:21
问题 Is there an ANSI SQL compliant version of SQL SERVER's SELECT TOP n ? 回答1: ANSI/ISO SQL:2003 introduced windowing functions : SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY age ASC) AS rownum, person_id, person_name, age FROM person ) AS foo WHERE rownum <= 3 Microsoft SQL Server has supported this syntax since SQL Server 2005. http://msdn.microsoft.com/en-us/library/ms189798(v=sql.90).aspx ANSI/ISO SQL:2008 introduced a simpler syntax for FETCH FIRST , which may be more analogous to

Connected Components

本小妞迷上赌 提交于 2019-12-18 18:10:01
问题 I have a set of data that has been created by matching together similar sub-items, and then GROUPing these similar items by "category". Now, the resultant categories must be matched in such a way that groups related categories together within each "group_id". In the example below, one match is A->B->C->D->E->F->G, which is obtained by recursing through rows. I've posted my current answer, which works on this simple data set, but because the actual data set contains up to 1M rows, and there

Connected Components

耗尽温柔 提交于 2019-12-18 18:09:11
问题 I have a set of data that has been created by matching together similar sub-items, and then GROUPing these similar items by "category". Now, the resultant categories must be matched in such a way that groups related categories together within each "group_id". In the example below, one match is A->B->C->D->E->F->G, which is obtained by recursing through rows. I've posted my current answer, which works on this simple data set, but because the actual data set contains up to 1M rows, and there

Implement Rank without using analytic function

冷暖自知 提交于 2019-12-17 19:56:46
问题 I am wondering if there is a method to implement SQL analytic functions without using the inbuilt functions. SELECT *, ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rownum, DENSE_RANK() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS denserank, RANK() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rnk FROM emp; 回答1: Here are the three equivalent expressions: select emp.*, (select count(*) from emp emp2 where emp2.dept_id = emp.dept_id and (emp2.salary > emp.salary

Oracle-Conveting SQL to ANSI SQL

大憨熊 提交于 2019-12-14 03:35:40
问题 This is regarding converting query to ANSI SQL. I tried writing this query with Oracle old syntax and it threw the following error so I ended up changing it as shown below . After researching, I found that ANSI SQL supports such requirements. ERROR :a table may be outer joined to at most one other table tips Here is the query that I wrote which is working but it would be great to know if there are ways this can be re-written in ANSI-SQL or by using old outer join syntax. I am looking for the

Conversion from Oracle to ANSI outer join

此生再无相见时 提交于 2019-12-13 07:12:46
问题 I have to rewrite a lot of SQL queries with Oracle outer join notation (+) to ANSI SQL. I read something about Oracle syntax but there were very easy examples. How should look this query in ANSI notation? SELECT * FROM realtion r1, relation r2 WHERE r1.relno=r2.relno(+) AND r.id(+)=10 or SELECT * FROM Mail M, Code C, Relation R WHERE M.STATUS = 2 AND C.id = M.usrID AND r.relo(+) = m.item AND R.item(+) = m.att 回答1: In a first query you have alias r, my guess it is r2. SELECT * FROM realtion r1

ANSI SQL 92: find last occurrence of character

强颜欢笑 提交于 2019-12-12 23:14:58
问题 I need a ANSI SQL 92 statement to change all characters following the last '/' character to lower case. On Sybase I would write: update table set col = left(col, len(col)-charindex('/', reverse(col))) || lower(right(col, charindex('/', reverse(col)))) I can find all functions in ANSI SQL 92 but the REVERSE function, that I just use to find the last occurrence of the slash. 来源: https://stackoverflow.com/questions/7241090/ansi-sql-92-find-last-occurrence-of-character

Changing SQL Server query to pure ANSI SQL query

三世轮回 提交于 2019-12-11 12:22:17
问题 I am working on a database system that uses SQL syntax. However I am unable to use the cross apply in the code below. Is there a way to rewrite this without applies? declare @rsBuildDetails table(dt datetime, build varchar(255), val varchar(255)); insert into @rsBuildDetails (dt, build, val) values ('20100101', '1', 'pass') ,('20100102', '2', 'fail') ,('20100103', '3', 'pass') ,('20100104', '4', 'fail') ,('20100105', '5', 'fail') ,('20100106', '6', 'fail') ,('20100107', '7', 'pass') ,(

Sybase *= to Ansi Standard with 2 different outer tables for same inner table

六月ゝ 毕业季﹏ 提交于 2019-12-11 04:39:08
问题 I am trying to migrate some legacy procedural code. I am having trouble figuring out the ANSI standard syntax to produce the same results. Below is one of the many combinations I have tried. What is the inner table for the second join, is it the output from the first join or is it the source table. Please help I have a lot of code to change. Original SQL Statement select * from JT1 a, JT2 b, JT3 c where a.ID *= b.ID and c.JOB *= b.JOB My Conversion select * from JT1 a left outer join JT2 b on