subquery

Select records in table A with *only* certain corresponding records in table B

北城以北 提交于 2019-12-12 03:48:50
问题 For example, say you have a table of files and a logging table of transfer operations. CREATE TABLE files ( id INTEGER PRIMARY KEY -- various other columns ); CREATE TABLE transfers ( id INTEGER PRIMARY KEY, file_id INTEGER, status TEXT NOT NULL, -- various other columns FOREIGN KEY (file_id) REFERENCES files (id) ) A transfer operation can have various statuses -- 'succeeded' , 'failed' , 'in progress' , etc. One file can have many transfer operations -- in particular, if a transfer fails,

Adding INNER JOIN to Query With Subquery With Inline Select Statement

丶灬走出姿态 提交于 2019-12-12 03:47:14
问题 I have the following SQL which works: Select TRADING_DWKEY, M_SM_USER_CODE, FIRST_TRADE, 'New Footprint' Status, Null Q4Vol, CQVol From (Select A.TRADING_DWKEY||A.RM_SM_USER_CODE, A.TRADING_DWKEY, A.RM_SM_USER_CODE, B.FIRST_TRADE, SUM(A.RISK_AMOUNT_ADJ)/1000000 CQVol from FACT_TRADE_ROLLUP A, (SELECT TRADING_DWKEY, MIN(FIRST_TRADE_DATE) FIRST_TRADE FROM ACCOUNT_FIRST_LAST_TRADE_DATES Having MIN(FIRST_TRADE_DATE) >= to_char(trunc((sysdate-1),'Y'),'dd-Mon-yy') GROUP BY TRADING_DWKEY) B WHERE A

sql to LINQ that has a CASE and a sub query

只谈情不闲聊 提交于 2019-12-12 03:07:32
问题 I have been strugging to convert the query below to a linq query, im pretty close but I am not sure how to add in a case statement to LINQ. Googling around got me this close. Original Working Query: SELECT *, CASE WHEN Recipe_Name IN (SELECT Recipe_Name FROM Recipes WHERE Status = 2) THEN 0 ELSE 1 END AS editable FROM Recipes WHERE Status = 1 ORDER BY Recipe_Name; My LINQ - Missing the case statement: var lcrecipes = from r in db.Recipes where r.Status == 2 select r.Recipe_Name; var

Inception situation with oracle (sub query stuffs)

岁酱吖の 提交于 2019-12-12 02:57:54
问题 For Oracle, From these tables, Table 1 CUSTOMER : has cust_fname, cust_lname, cust_id Table 2 SALESORDER : has so_number, so_custid Table 3 ITEM : has item_qty, item_sonum while CUST_ID = SO_CUSTID and SO_NUMBER = ITEM_SONUM (FK relationship) I want to show customer name with full name (means cust_fname+cust_lname) whereas this customer (just one) is the one who had ordered the highest numbers of items (means has to do something with item_qty). How can I write a code for this task? Thank you

ORA-00934: Group function not allowed here || Selecting MIN(Salary) of highest paid dept

微笑、不失礼 提交于 2019-12-12 02:29:31
问题 O community, do you know how I could select the department_ID, and lowest salary of the department with the highest average salary? Or how to eliminate the'ORA-00934: group function not allowed here' issue? Would I need to use two subqueries? So far, this is what I've come up with, trying to get the department_ID of the highest paid department: SELECT department_ID, MIN(salary FROM employees WHERE department_ID = (SELECT department_ID FROM employees WHERE salary = MAX(salary)); Thank you,

MySQL Update a field value with subquery with multiple returning rows

本小妞迷上赌 提交于 2019-12-12 02:06:12
问题 I have two tables "bank" and "bonds". Each user has a bank record but can have 0, 1, or more bonds records. I want to write a script that updates the field "cash" in the "bank" table with the interests of the multiple bonds a user might hold. The interest is calculated by issuePrice * coupon fields of the "bonds" table. But since a user might hold multiple bonds, it should do this for each bond. At the moment, I tried something like this: $MySQL->db_Query("UPDATE bonds bo, bank ba SET ba.cash

ORA-00932: inconsistent datatypes: expected - got CLOB 00932. 00000

蹲街弑〆低调 提交于 2019-12-12 01:47:11
问题 I have column response_xml and request_xml which consist of large string. I have used substring function for this large string in order to fetch the SUBSCRIPTION_ID from response_xml and orderType from request_xml. The query is working fine. But now i want to put condition for this query such that it should only return SUBSCRIPTION_ID where orderType='NEW'. I used the below query but resulting an error as ORA-00932: inconsistent datatypes: expected - got CLOB 00932. 00000 - "inconsistent

Postgresql subquery execution within ON UPDATE rule (maybe bug in postgresql?)

半腔热情 提交于 2019-12-12 01:27:16
问题 I am running into a strange behavior (or is this a bug within postgresql?) within postgresql's execution order of subqueries within rules. Consider the following SQL: BEGIN; CREATE OR REPLACE FUNCTION debug(anyelement) RETURNS bool AS $$ pg_raise('notice', 'debug(): ' . json_encode($args[0])); RETURN TRUE; $$ LANGUAGE PLPHP IMMUTABLE STRICT; CREATE TABLE foo_table (c1 text); CREATE OR REPLACE RULE foo_update_rule AS ON UPDATE TO foo_table DO INSTEAD ( WITH foobar_update AS ( SELECT unnest('{a

MYSQL Select Subquery IF exists

谁说我不能喝 提交于 2019-12-12 01:23:05
问题 I have 3 tables ....users, updates and bumps. I want to return the user making the api request a feed updates in most recent order with all the needed data to display each of the statuses in the feed. I also need to include whether the update has been "bumped" by the user making the api request or not (bumped = liking a status on facebook) In a nutshell this is what I am trying to do even though the if count area of this query is no where near correct syntax: SELECT b.type,b.owner,b.update

informatica multi correlated subquery implementation

独自空忆成欢 提交于 2019-12-12 01:20:20
问题 I am facing a task that due to my lack of experience with Informatica Components, in particular SQL Transformation, I did not implemented yet. So what would be the best approch in PowerCenter to implement this kind of subquery: SELECT A.ID, NVL2(A.SACHKONTO, B.KLAMMER, A.ID) AS KLAMMER FROM Table1 A, (SELECT A.ID AS KLAMMER, B.ID FROM (SELECT ID, ID AS VON_ID, LEAD(ID,1) OVER (ORDER BY ID) - 1 AS BIS_ID FROM Table1 WHERE SACHKONTO IS NULL) A, Table1 B WHERE B.ID BETWEEN A.VON_ID AND A.BIS_ID