join

Conditional JOIN different tables

大城市里の小女人 提交于 2020-01-28 04:07:53
问题 I want to know if a user has an entry in any of 2 related tables. Tables USER (user_id) EMPLOYEE (id, user_id) STUDENT (id, user_id) A User may have an employee and/or student entry. How can I get that info in one query? I tried: select * from [user] u inner join employee e on e.user_id = case when e.user_id is not NULL then u.user_id else null end inner join student s on s.user_id = case when s.user_id is not NULL then u.user_id else null end But it will return only users with entries in

Conditional JOIN different tables

只愿长相守 提交于 2020-01-28 04:07:08
问题 I want to know if a user has an entry in any of 2 related tables. Tables USER (user_id) EMPLOYEE (id, user_id) STUDENT (id, user_id) A User may have an employee and/or student entry. How can I get that info in one query? I tried: select * from [user] u inner join employee e on e.user_id = case when e.user_id is not NULL then u.user_id else null end inner join student s on s.user_id = case when s.user_id is not NULL then u.user_id else null end But it will return only users with entries in

Joining a set of ordered-integer yielding Python iterators

99封情书 提交于 2020-01-28 03:33:07
问题 Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence. After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Python, as seen here (though that version is quite old now). My problem is with the search() function, which must iterate over each posting list and yield only the document IDs that appear on

反转字符串中的单词

我与影子孤独终老i 提交于 2020-01-26 11:50:05
第一种 export default (str) => { // 字符串按空格进行分隔,保存数组,数组的元素的先后顺序就是单词的顺序 let arr = str.split(' ') // 对数组进行遍历,然后每个元素进行反转 let result = arr.map(item => { return item.split('').reverse().join('') }) return result.join(' ') } 第二种 export default (str) => { // 1. 字符串按空格进行分隔,保存数组,数组的元素的先后顺序就是单词的顺序 // 2. 对数组进行遍历,然后每个元素进行反转 return str.split(' ').map(item => { return item.split('').reverse().join('') }).join(' ') } 第三种 export default (str) => { // 1. 字符串按空格进行分隔,保存数组,数组的元素的先后顺序就是单词的顺序 // 2. 对数组进行遍历,然后每个元素进行反转 return str.split(/\s/g).map(item => { return item.split('').reverse().join('') }).join(' ') } 第四种

SQL学习笔记:高级教程

十年热恋 提交于 2020-01-26 04:32:40
SQL语法 LIMIT select col from table limit number select * from table limit number LIKE select * from table where col LIKE '%in%' select * from table where col NOT LIKE '%in%' 通配符 通配符必须与LIKE一起使用 % -- 替代一个或者多个字符 _ -- 替代一个字符 [charlist] -- 字符列中的任何单一字符 [!charlist] -- 不在字符列中的任何单一字符 select * from table where col LIKE '[abc]d_e%' IN 在where中选取多个值 select * from table where col IN ('zhi1', 'zhi2') BETWEEN ... AND ... select * from table where col BETWEEN 'a' AND 'c' select * from table where col NOT BETWEEN 'a' AND 'c' Alias select A.col, B.col1 from table1 AS A, table2 AS B where A.col = 'zhi1' AND B.col

Myql pivot join fails

旧街凉风 提交于 2020-01-26 03:57:06
问题 I have following tables Tags id | tag_name | slug | 1 | tag1 |tag1 2 | tag1 |tag1 products id | proudct_name 1|product1 2|product2 product_tags id | product_id | tag_id 1|1||1 2|1|2 3|2|1 i need retrieve only those product which belongs to both tag1 and tag2 select * from `products` INNER JOIN product_tags ON products.id=product_tags.product_id INNER JOIN tags ON tags.id=product_tags.tag_id WHERE product_tags.tag_id=1 AND product_tags.tag_id=2 But my query return empty result 回答1: This will

SQL Join two tables, only get latest entry of second table

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-25 20:25:06
问题 I have these two tables: items itemname description belongs A1 some_text user1 A2 some_text user1 A3 some_text user1 A4 some_text user1 A5 some_text user1 A1 some_text user2 B2 some_text user2 movements itemname start_date end_date belongs A1 2013-02-01 2014-01-12 user1 A1 2014-08-14 NULL user1 A1 2014-10-15 2015-01-01 user1 A2 2013-08-03 2014-08-14 user1 A2 2014-08-14 NULL user1 A3 2013-08-02 2014-08-20 user1 A3 2013-12-05 2014-01-07 user1 A4 2013-07-15 2014-09-13 user1 A4 2014-09-13 NULL

Confused by JOINs - data missing in result

给你一囗甜甜゛ 提交于 2020-01-25 16:52:44
问题 This thread is related with my older one Combine fields from different rows on condition. I adjusted the query I got from this thread to meet some other requirements. SELECT a.Date, a.orderid AS AZNr, a.Typ, ROUND(a.Fees, 2) AS Fees, ROUND(b.Shipping, 2) AS Shipping, ROUND(c.Price, 2) AS Price, d.DeliveryLand FROM (SELECT posteddate AS Date, transactiontype AS Typ, orderid, SUM(amount) AS Fees FROM report WHERE amounttype = 'ItemFees' GROUP BY orderid) a LEFT JOIN (SELECT orderid, SUM(amount)

正则实现整数运算

不羁岁月 提交于 2020-01-25 16:46:58
加 const sum = ( m , n ) => { m = Array ( m + 1 ) . join ( '#' ) ; n = Array ( n + 1 ) . join ( '#' ) ; return m . replace ( /$/ , n ) . length ; } ; sum ( 3 , 2 ) ; // 5 减 const diff = ( m , n ) => { m = Array ( m + 1 ) . join ( '#' ) ; n = Array ( n + 1 ) . join ( '#' ) ; return m . replace ( n , '' ) . length ; } ; diff ( 3 , 2 ) ; // 1 乘 const product = ( m , n ) => { m = Array ( m + 1 ) . join ( '#' ) ; n = Array ( n + 1 ) . join ( '#' ) ; return m . replace ( /\#/g , n ) . length ; } ; product ( 3 , 2 ) ; // 6 除 const division = ( m , n ) => { m = Array ( m + 1 ) . join ( '#' ) ; n =

What kind of join between 2 SQL table that they don't have common id?

情到浓时终转凉″ 提交于 2020-01-25 13:16:25
问题 I have a SQL table consists of id, name, email,.... I have another SQL table that has id, email, emailstatus but these 2 id are different they are not related. The only thing that is common between these 2 tables are emails. I would like to join these 2 tables bring all the info from table1 and if the email address from table 1 and table 2 are same and emailstatus is 'Bounced'. But the query that I am writing gives me more record than expected. Can you help? Also I am not even sure that it is