join

how do I perform a vlookup equivalent operation on my dataframe with some additional conditions

扶醉桌前 提交于 2021-02-11 13:58:39
问题 HI I am trying to run lookup equivalent function on python but having tried merge and join I haven't hit the nail yet. so my first df is this list = ['Computer', 'AA', 'Monitor', 'BB', 'Printer', 'BB', 'Desk', 'AA', 'Printer', 'DD', 'Desk', 'BB'] list2 = [1500, 232, 300, 2323, 150, 2323, 250, 2323, 23, 34, 45, 56] df = pd.DataFrame(list,columns=['product']) df['number'] = list2 This is how the df would look product number 0 Computer 1500 1 AA 232 2 Monitor 300 3 BB 2323 4 Printer 150 5 BB

Select MCQ answer count based on previous question's answer

人盡茶涼 提交于 2021-02-11 12:49:52
问题 Let's take a PostgreSQL DB with the following structure: (all the relations from top to down are OneToMany ) Where a Brandlift always has exactly 2 brandlift_question each having 1 brandlift_answer (itself having many brandlift_answer_content ) by brandlift_respondent Goal: Given a 'brand' (let's call it the "flagship brand") and a brandlift.campaign_id , for each brand of this brandlift , retrieve by respondent segment , the count of brand.id = 'answer_content.brand_id' of the second (right)

SQL JOIN with negative WHERE condition

若如初见. 提交于 2021-02-11 12:32:30
问题 I have two tables Document and Label (not my real case, I am using analogy). One Document can have N Labels. When I need to select Documents that has listed labels I can do easily this select D.id from document D join label L on D.id = L.document_id where L.value in('label1','label2',...) How to write a query where I need Documents that DO NOT have listed labels? When I do this select D.id from document D join label L on D.id = L.document_id where L.value not in('label1','label2',...) then it

Joining three table then group

自作多情 提交于 2021-02-11 07:36:09
问题 I am going to join three tables then sum one of the column multiplied with an value from another. SELECT t1.column, t2.column, SUM(t1.column * t2.column) FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id JOIN table3 t3 ON t2.id = t3.id GROUP BY t1.column, t2.column; This query does what I want, BUT I do not understand why the GROUP BY works? If I add columns to the select must I also add columns to the group by? 回答1: Do you actually know what you are doing here? SELECT t1.column, t2.column

SQL JOIN: Just not able to understand them

夙愿已清 提交于 2021-02-11 05:55:59
问题 Now, I know know this question related to JOIN have been asked many times. I went through many of them. But it still isn't clear to me. I read these aricles too: http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins#_comments and http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html but no, it still didn't help. I do understand the Vein diagrams mathematically but not able to grab basic concept behind JOIN . Suppose I have two tables. tbl

Replacing null based on a condition

泪湿孤枕 提交于 2021-02-11 04:24:13
问题 I am having a table with many columns (but posting only col1, col2, col3 here for simplified post): id col1 col2 col3 source_id a1 765.3 23-Apr-08 cat a5 a2 3298.3 (null) dog a4 a3 8762.1 27-Nov-10 rat a8 a4 (null) (null) (null) (null) a5 (null) (null) (null) a6 a6 (null) (null) (null) (null) I want to fill null values of source _id with values from id . For example, source_id a5 row has null which has to replaced with id a1 values , subsequently, source_id a6 row having null to be replaced

Replacing null based on a condition

梦想与她 提交于 2021-02-11 04:24:13
问题 I am having a table with many columns (but posting only col1, col2, col3 here for simplified post): id col1 col2 col3 source_id a1 765.3 23-Apr-08 cat a5 a2 3298.3 (null) dog a4 a3 8762.1 27-Nov-10 rat a8 a4 (null) (null) (null) (null) a5 (null) (null) (null) a6 a6 (null) (null) (null) (null) I want to fill null values of source _id with values from id . For example, source_id a5 row has null which has to replaced with id a1 values , subsequently, source_id a6 row having null to be replaced

Replacing null based on a condition

给你一囗甜甜゛ 提交于 2021-02-11 04:23:24
问题 I am having a table with many columns (but posting only col1, col2, col3 here for simplified post): id col1 col2 col3 source_id a1 765.3 23-Apr-08 cat a5 a2 3298.3 (null) dog a4 a3 8762.1 27-Nov-10 rat a8 a4 (null) (null) (null) (null) a5 (null) (null) (null) a6 a6 (null) (null) (null) (null) I want to fill null values of source _id with values from id . For example, source_id a5 row has null which has to replaced with id a1 values , subsequently, source_id a6 row having null to be replaced

How to make sql join query in laravel 5?

不打扰是莪最后的温柔 提交于 2021-02-10 22:31:34
问题 Hi I want to get data from database, I am using join query but I have got this error: QueryException in Connection.php line 673: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'surat_masuk' (SQL: select jenis_surat . jenis_surat , surat_masuk . nomor_surat , surat_masuk . perihal , surat_masuk . tanggal_publish from surat_masuk inner join jenis_surat on id_jenis_surat = jenis_surat . id_jenis_surat inner join surat_masuk on id_jenis_surat = surat_masuk . id

How to make sql join query in laravel 5?

泄露秘密 提交于 2021-02-10 22:31:20
问题 Hi I want to get data from database, I am using join query but I have got this error: QueryException in Connection.php line 673: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'surat_masuk' (SQL: select jenis_surat . jenis_surat , surat_masuk . nomor_surat , surat_masuk . perihal , surat_masuk . tanggal_publish from surat_masuk inner join jenis_surat on id_jenis_surat = jenis_surat . id_jenis_surat inner join surat_masuk on id_jenis_surat = surat_masuk . id