derived-table

Pull columns from derived table and sum them in one MySQL SELECT statement

家住魔仙堡 提交于 2019-12-31 05:21:44
问题 I need to pull column data from two tables, run calculations on the data with the result saved as an alias, and then sum those results into other alias' to display in a php table. I am trying to achieve this by creating a derived table within my SELECT statement but it doesn't work. I don't receive any errors but my table only displays the column headers. CODE: $sql = "SELECT x.company, x.stagestatus, x.shippeddate, SUM(x.totprice) as totalprice, SUM(x.sgtotquantity) as sgtotqty, SUM(x

Pull columns from derived table and sum them in one MySQL SELECT statement

百般思念 提交于 2019-12-31 05:21:07
问题 I need to pull column data from two tables, run calculations on the data with the result saved as an alias, and then sum those results into other alias' to display in a php table. I am trying to achieve this by creating a derived table within my SELECT statement but it doesn't work. I don't receive any errors but my table only displays the column headers. CODE: $sql = "SELECT x.company, x.stagestatus, x.shippeddate, SUM(x.totprice) as totalprice, SUM(x.sgtotquantity) as sgtotqty, SUM(x

Jaspersoft Derived Table error when running SELECT query

拜拜、爱过 提交于 2019-12-25 07:10:37
问题 I'm currently running a SELECT query in the derived tables part of creating a domain in Japsersoft's AWS BI Suite. However when I do, I get the following error: com.jaspersoft.commons.semantic.metaapi.MetaDataException: Cannot execute JDBC Query. org.postgresql.util.PSQLException: ERROR: transaction is read-only Does anyone know why this could be and if so point me in the right direction? 回答1: According to a Jaspersoft forum post, this can be solved by installing the latest PostgreSQL JDBC

SQL derived table results in unknown column

☆樱花仙子☆ 提交于 2019-12-24 06:35:50
问题 +------------------+ +------------------+ | object | | example | +------------------+ +------------------+ | id | | id | | table_name | | ... | | ref_id | | | +------------------+ +------------------+ object [ id = 5, table_name = example, ref_id = 2] example [ id = 2 ] I have a table which can represent a group of objects originating from a number of different tables. These objects all have an id , referenced by object.ref_id . I am trying to select the original object (from the table

Query using a derived table with ISNUMERIC results in conversion failure (varchar to int)

拈花ヽ惹草 提交于 2019-12-24 00:45:45
问题 Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'), ('123'), ('abc'), ('124') SELECT * FROM ( SELECT * FROM @table WHERE ISNUMERIC(loc) = 1 ) as a WHERE CAST(loc as INT) BETWEEN 100 AND 200 If I have some varchar values and I limit them to numeric values using ISNUMERIC in a derived table in the query, why does it result in a conversion error?: Conversion failed when converting the varchar value '134a' to data type int. Is there a way around

Derived account balance vs stored account balance for a simple bank account?

半世苍凉 提交于 2019-12-18 09:54:08
问题 So, its like our normal bank accounts where we have a lot of transactions which result in inflow or outflow of money. The account balance can always be derived by simply summing up the transaction values. What would be better in this case, storing the updated account balance in the database or re-calculating it whenever needed? Expected transaction volume per account: <5 daily Expected retrieval of account balance: Whenever a transaction happens and once a day on an average otherwise. How

Place an Insert Statement into a Select Statement

牧云@^-^@ 提交于 2019-12-12 04:07:00
问题 I have read the other questions and all of the posted comments/answers to questions that are similar to this one. None of them seem to answer this question directly. I am wanting to know if there is a way to either concatenate or place an INSERT , DELETE or UPDATE statement into a SELECT statement. If so how? Could this be done by using a derived table function or a subSelect statement? And example would be: INSERT INTO Customer (name) VALUES 'Test Name' but place this into a SELECT statement

Oracle sql derived table - optional aliasing

a 夏天 提交于 2019-12-11 11:33:02
问题 I came across a client's query yesterday, it is something like: select count(*) as countall, person, location from (select custid, min("Date") as theDate, person, data.location from data join customer on customer.customerid = custid where status = 1 and custid <> -1 group by custid, person, data.location) --[NO ALIAS] group by person,location I don't have a lot of hours in Oracle, but in MS SQL this would not fly, to my knowledge. Any time I have used a derived table it throws an error, so to

A Derived Field in an SQLite3 Database

不想你离开。 提交于 2019-12-11 00:32:02
问题 Good Evening everyone, Today I would like to ask a question relating to derived fields (also known as calculation fields) in SQLite3. Utilizing two values stored within my database "weight" and "distance" I know it is possible to utilize them to perform calculations to return the value I want utilizing a formula that requires both. However I am wondering if there is a way to set a field, by SQLite coding, to automatically generate its own value, so once they have entered there weight and

Subquery's rand() column re-evaluated for every repeated selection in MySQL 5.7/8.0 vs MySQL 5.6

[亡魂溺海] 提交于 2019-12-09 13:46:18
问题 I am doing a subquery in which I have a calculated column involving random number generation. In the base query I select this column twice. MySQL 5.6 works as I expect, the calculated value being called once and fixed. The 5.7+/8.0+ execution seems to re-evaluate the subquery's column value individually for each selection. Is this correct behavior? What can I do to force it work as expected in newer versions of MySQL? CREATE TABLE t ( `id` BIGINT(20) NOT NULL PRIMARY KEY AUTO_INCREMENT )