Count records from two tables with foreign keys – Mysql
Suppose I have these MySql tables: TABLE_PEOPLE id name 1 John 2 Albert 3 Joanna 4 Mike 5 Norton TABLE_COLOR id people_id colors 1 1 Green 2 1 Red 3 3 Yellow 4 3 Blue 5 2 Green 6 4…
Suppose I have these MySql tables: TABLE_PEOPLE id name 1 John 2 Albert 3 Joanna 4 Mike 5 Norton TABLE_COLOR id people_id colors 1 1 Green 2 1 Red 3 3 Yellow 4 3 Blue 5 2 Green 6 4…
I have two tables. StudentGroup and StudentGroupsMembers. StudentGroup.id = StudentGroupMembers.group_id is the foreign key relation. sg = StudentGroup.joins(:student_group_members).select(" student_groups.id, student_groups.name, count(student_group_members.id) as cnt ").group('student_group_members.group_id, student_groups.name, student_groups.id').where(id: [3,4,5,6,6,7,7,8,8]).where("student_group_members.member_type='ra'") This return ActiveRecord_Relation [#<StudentGroup:0x00007fc11253d088 id: 3, name: "Blah">, #<StudentGroup:0x00007fc11253cc78 id: 4, name: "Foo">,…
I need to get the most used content text of elements within a certain class. In my case the most recurrent phrase of elements: Service number 1 <div class="service_list"> <span>Service number 1</span> <span>Service number 2</span> </div> <div class="service_list"> <span>Service number…
I need to get the most used content text of elements within a certain class. In my case the most recurrent phrase of elements: Service number 1 <div class="service_list"> <span>Service number 1</span> <span>Service number 2</span> </div> <div class="service_list"> <span>Service number…
Hello i im trying to count the values within each range e.g. between 115000 - 120000 in my DURATION_IN_MS column. my column looks like this: 119631 120689 143498 119798 WITH tab1 AS( SELECT TOP 30 * FROM MACHINE_PROCESSING_DURATION_EVALUATION WHERE START_TIMESTAMP…
I have Data which indicates month of Order date and month of Shipment date. I want to convert the records which will show, in each month, what is the count of orders and in same month what is the count…
Have a problem with total count of ajax searche's results. There is a mistake "Method IlluminateDatabaseEloquentCollection::total does not exist." if I use directive for example <div class="searched-item"> <a href="#" class="searched-item-res1">{{ __('main.res_found') }} {{$sfilms->total()}} {{ __('main.res_results') }}</a> </div> How to fix…
I wanted to delete all records except the one with the highest value so I did CREATE TABLE code ( id SERIAL, name VARCHAR(255) NOT NULL , value int NOT NULL ); INSERT INTO code (name,value) VALUES ('name',1); INSERT INTO…
I have two tables with one referencing the other. CREATE TABLE blogs ( article LONGTEXT, id VARCHAR(255) PRIMARY KEY ); CREATE TABLE blog_eval ( blog_id VARCHAR(255) REFERENCES blogs(id) ON DELETE CASCADE, user_id VARCHAR(255) REFERENCES users(id), is_like BOOLEAN, --true if like…
I'm trying to join 2 tables and count the number of entries for unique variables in one of the columns. In this case I'm trying to join 2 tables - patients and trials (patients has a FK to trials) and…