inner-join

Advance query. Rank most related fields in mysql

江枫思渺然 提交于 2019-12-07 22:44:38
问题 Let's assume we have a database like this: Project_tbl : ----------------- id | Project_name ----------------- 1 | A 2 | B 3 | C ----------------- personel_project_tbl : -------------------- user_id | Project_id -------------------- 1 | 1 2 | 2 3 | 1 3 | 2 2 | 3 -------------------- instrument_project_tbl : -------------------------- instrument_id | Project_id -------------------------- 1 | 1 1 | 2 2 | 2 2 | 1 1 | 3 -------------------------- Now, I need to sort the list of projects and rank

inner join with multiple conditions r data table

雨燕双飞 提交于 2019-12-07 16:49:58
问题 I am trying to do an inner join using data table that has multiple, fairly dynamic conditions. I am getting tripped up on the syntax. First, I create two objects, x and x2 that I want to do an inner join with. set.seed(1) #generate data x = data.table(CJ(t=1:10, d=1:3,p1s=seq(1,3,by=0.1),p1sLAST=seq(1,3,by=0.1))) x[d==1,p1sLAST:=3] x=x[p1s<=p1sLAST] x2 = data.table(CJ(tprime=1:10, p1sLASTprm=seq(1,3,by=0.1))) With the objects: > x t d p1s p1sLAST 1: 1 1 1.0 3.0 2: 1 1 1.0 3.0 3: 1 1 1.0 3.0 4

Can a list field be a shard key in MongoDB?

此生再无相见时 提交于 2019-12-07 01:01:35
Have some data that looks like this: widget: { categories: ['hair', 'nails', 'dress'] colors: ['red', 'white'] } The data needs to be queried like this: SELECT * FROM widget_table WHERE categories == 'hair' AND colors == 'red' Would like to put this data into a MongoDB sharded cluster. However, it seems like an ideal shard key would not be a list field. In this case, that is not possible because all of the fields are list fields. Is it possible to use a list field, such as the field categories as the shard key in MongoDB? If so, what things should I look out for / be aware of? Thanks so much!

Django Inner Join Queryset

扶醉桌前 提交于 2019-12-06 17:56:16
问题 I'm working with Django and I need to do a queryset using two inner joins. I have three models A, B, and C and I want to do a query like the following in psql: select DISTINCT a from A inner join B on B.a_id = A.id inner join C on C.b_id = B.id; Models: (only included relevant fields) class A(models.Model): id = models.IntegerField(primary_key=True) class B(models.Model): id = models.IntegerField(primary_key=True) a = models.ForeignKey(A, null=True, blank=True,on_delete=models.SET_NULL) class

How to improve query performance with order by, group by and joins

做~自己de王妃 提交于 2019-12-06 15:27:42
I Had a problem with order by when joins multiple tables which have millions of data. But I got solution as instead of join with distinct use of EXISTS will improve performance from the following question How to improve order by performance with joins in mysql SELECT `tracked_twitter` . *, COUNT( * ) AS twitterContentCount, retweet_count + favourite_count + reply_count AS engagement FROM `tracked_twitter` INNER JOIN `twitter_content` ON `tracked_twitter`.`id` = `twitter_content`.`tracked_twitter_id` INNER JOIN `tracker_twitter_content` ON `twitter_content`.`id` = `tracker_twitter_content`.

creating a mysql table from a inner join

╄→尐↘猪︶ㄣ 提交于 2019-12-06 11:52:07
I'm trying to create a mysql table from the inner join between two other tables. I'm dealing with a database someone creates which has the following tables: sitematrix_sites sitematrix_databases They are related by another table (I don't know why don't use a foreign key) called sitematrix_sites_databases which has the following fields: site_id and database_id . That's how the two tables relate. Now I'm trying to remove that to make my life easier, so I have: mysql> CREATE TABLE result AS(select * from sitematrix_databases INNER JOIN site matrix_site_databases ON sitematrix_site_databases

Doing Join query using CDBCriteria

强颜欢笑 提交于 2019-12-06 11:15:26
I am trying to do a Join query using CDBCriteria in Yii framework. The issue is the join query works successfully but it does not display the columns from other tables. I am doing in the following way $criteria = new CDbCriteria; $criteria->order = 't.id desc'; $criteria->select = '*'; $criteria->join = ' INNER JOIN table2 INNER JOIN table3 INNER JOIN table4'; When i run this, I can see only the mail table1 columns displayed. Other columns are not shown. In my model class, I have the relation has public function relations() { // NOTE: you may need to adjust the relation name and the related //

Conditional inner join statements in MySQL

廉价感情. 提交于 2019-12-06 09:19:09
问题 Is there a way I can conditionally change which table i'm inner joining on based on the value of a field in another table? Here's what I got so far (but it errors) out: SELECT j.jobID, j.jobNumber, CASE WHEN j.idType = 'dealership' THEN d.dealershipName WHEN j.idType = 'Group' THEN g.groupName WHEN j.idType = 'Agency' then a.agencyName END as dealershipName, CASE WHEN p.manualTimestamp != '0000-00-00 00:00:00' THEN UNIX_TIMESTAMP(p.manualTimestamp) WHEN p.manualTimestamp = '0000-00-00 00:00

inner join with empty result from right table

无人久伴 提交于 2019-12-06 07:20:18
问题 I have 2 tables, restaurants and orders, each restaurant can have many orders restaurants table id name orders table id restaurant_id date I need to find the restaurants that have no orders on some date range. In orders table I save the order dates like - each row represents one day. So, I need to make inner join, but with no results from the orders table. Say, I need to find restaurants that are free from 2013-08-09 to 2013-08-11 date range. How can I achieve this ? How to make a query, that

How can I sum a group of sums? SQL Server 2008

二次信任 提交于 2019-12-06 05:59:12
问题 I have a query with a sum in it like this: SELECT Table1.ID, SUM(Table2.[Number1] + Table2.[Number2]) AS SumColumn FROM Table1 INNER JOIN Table3 ON Table1.ID = Table3.ID INNER JOIN Table2 ON Table3.ID = Table2.ID WHERE (Table2.[Something] = 'Whatever') GROUP BY Table1.ID, Table2.[Number1] , Table2.[Number2] and it gives me a table like this: ID SumColumn 67 1 67 4 70 2 70 6 70 3 70 6 80 5 97 1 97 3 How can I make it give me a table like this, where the SumColumn is summed, grouped by the ID