sql-view

MySQL - create view using subquery in FROM clause

别说谁变了你拦得住时间么 提交于 2019-12-04 03:50:18
问题 I want to create view in MySQL using a subquery CREATE OR REPLACE VIEW `V_TASK_TRANSFER` (`REF_ID`, `DATE_CREATE`, `DATE_TRX`, `ACCOUNT_NO`, `TO_ACCOUNT_NO`, `TO_NAME`, `CURRENCY_CODE`, `AMOUNT`, `TASK_TYPE`, `NAME_E`, `NAME_I`, `REF_NO`, `EXECUTION_TYPE`, `REVIEW_COUNT`, `REVIEW_NEED`, `APPROVE_COUNT`, `APPROVE_NEED`, `TRX_COUNT_SUCCESS`, `TRX_COUNT_FAIL`, `TRX_COUNT_ALL`, `STATUS_TF`, `USER_ID` ) AS SELECT REF_ID, DATE_CREATE, DATE_TRX, ACCOUNT_NO, TO_ACCOUNT_NO, TO_NAME, CURRENCY_CODE,

Select a sequence between two numbers on MySQL

自闭症网瘾萝莉.ら 提交于 2019-12-03 14:50:20
I have this table named people with two dates on MySQL: | Name | start_date | end_date | | John | 2007-03-01 | 2009-10-12 | | Mike | 2001-06-06 | 2010-12-01 | I want to create a view that lets me search by activity year, being activity year any year between the start_date and the end_date . So, I'd like to get a field with a sequence of years, like this: | Name | activity_years | | John | 2007,2008,2009 | | Mike | 2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 | I've tried some approaches, but I can't get it. Since I want to create a view, I have to do it everything inside a SELECT

Data from two tables into one view

假如想象 提交于 2019-12-03 10:43:29
Is it possible to grab data from two tables (that have the same fields) into one view. Basically, so the view sees the data as if it was one table. Yes, using a UNION - CREATE VIEW vw_combined AS SELECT * FROM TABLE1 UNION ALL SELECT * FROM TABLE2 ...requires that there be the same number of columns, and the data types match at each position. ..preferrably, using a JOIN: CREATE VIEW vw_combined AS SELECT * FROM TABLE1 t1 JOIN TABLE2 t2 ON t2.col = t1.col But I want to warn against depending on views - if not materialized, they are only prepared SQL statements. There's no performance benefit,

Select Columns of a View

不打扰是莪最后的温柔 提交于 2019-12-03 10:26:36
I'm attempting to select the column names of a view in a similar way as selecting from information_schema.columns . I can't seem to find a way to do this. Has anyone else done this before or know if it is even possible? information_schema.columns.Table_name (at least under Sql Server 2000) includes views, so just use SELECT * FROM information_schema.columns WHERE table_name = 'VIEW_NAME' Try this: SELECT * FROM sys.views This gives you the views as such - if you need the columns, use this: SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('dbo.YourViewNameHere') Not sure how you can do it

creating django model for existing database/sql view?

安稳与你 提交于 2019-12-03 04:08:39
I have inserted a definition for a view in $template_dir/sql/$someTableName.sql file. (create or replace view) so every time I run syncdb , the db views are created. Can I create in models.py a python class which accesses that view? Is it better practice to just use python's raw sql functionality instead? ---EDIT--- Another problem I have is that the view doesn't have a primary key, but django seems to be assuming there will be one because I get an error caught an exception while rendering: (1054, "Unknown column 'appName_currentleagues.id' in 'field list'") But I don't have such a member

SQL view with dynamic count of columns

蹲街弑〆低调 提交于 2019-12-02 13:52:21
问题 I know it is impossible directly, but maybe with help of sql functions it is possible to create view with dynamic column count? What exactly I want to do is - Create view which's columns would be username (first table's values), date (second table's values), and multiple columns for properties (each third table's row would be column).User table structure - ID and username, Date table structure - ID and datetime, Property table structure - ID, property name, property value, fk user ID (plus

Do Jpa& Hibernate load data which changes asynchronously in DB?

血红的双手。 提交于 2019-12-02 05:36:19
问题 I have an oracle view in which I query my db. create or replace view my_view as Select cc.CCID ccid sm.SMCODE smcode, NVL(sm.smname, cc.ccname) sname From CC cc Inner Join SM sm On cc.id = sm.id; I use jpa 2.1 and hibernate 4.3.7 to map my view to my entity. My entity class looks like this: public class CCRequest implements Serializable { private static final long serialVersionUID = 1L; private String ccId; private String smCode; private String sName; } And my mapping xml looks like this: <

MySQL - create view using subquery in FROM clause

半城伤御伤魂 提交于 2019-12-01 19:42:00
I want to create view in MySQL using a subquery CREATE OR REPLACE VIEW `V_TASK_TRANSFER` (`REF_ID`, `DATE_CREATE`, `DATE_TRX`, `ACCOUNT_NO`, `TO_ACCOUNT_NO`, `TO_NAME`, `CURRENCY_CODE`, `AMOUNT`, `TASK_TYPE`, `NAME_E`, `NAME_I`, `REF_NO`, `EXECUTION_TYPE`, `REVIEW_COUNT`, `REVIEW_NEED`, `APPROVE_COUNT`, `APPROVE_NEED`, `TRX_COUNT_SUCCESS`, `TRX_COUNT_FAIL`, `TRX_COUNT_ALL`, `STATUS_TF`, `USER_ID` ) AS SELECT REF_ID, DATE_CREATE, DATE_TRX, ACCOUNT_NO, TO_ACCOUNT_NO, TO_NAME, CURRENCY_CODE, AMOUNT, TASK_TYPE, NAME_E, NAME_I, REF_NO, EXECUTION_TYPE, REVIEW_COUNT, REVIEW_NEED, APPROVE_COUNT,

PostgreSQL Views: Referencing one calculated field in another calculated field

大憨熊 提交于 2019-12-01 17:50:07
I have the same question as #1895500 , but with PostgreSQL not MySQL. How can I define a view that has a calculated field, for example: (mytable.col1 * 2) AS times_two ... and create another calculated field that's based on the first one: (times_two * 2) AS times_four ...? Depending on how heavy the formla is, you could use a subquery: select inner.*, times_two * 2 from (select mycol * 2 as times_two from table) sub Or rewrite the computation: select mycol * 2, mycol * 2 * 2 from table Use this statement CREATE VIEW view_name as SELECT column_name*2 as new_col1 , column_name*4 as new_col2 from

PostgreSQL Views: Referencing one calculated field in another calculated field

回眸只為那壹抹淺笑 提交于 2019-12-01 16:15:38
问题 I have the same question as #1895500, but with PostgreSQL not MySQL. How can I define a view that has a calculated field, for example: (mytable.col1 * 2) AS times_two ... and create another calculated field that's based on the first one: (times_two * 2) AS times_four ...? 回答1: Depending on how heavy the formla is, you could use a subquery: select inner.*, times_two * 2 from (select mycol * 2 as times_two from table) sub Or rewrite the computation: select mycol * 2, mycol * 2 * 2 from table