Drupal 8, Views: Count how many children have a reference to the parent

Explanations:

1) I have a node “parent”

2) I have 2 nodes “child”

3) Each child has a reference field (filled with a reference to the node “parent”)

Now, I’m trying to create a list with the Views module.

First problem: This list is a list of “parent” nodes AND should include a column with the following result: COUNT(child with a reference to the parent).

Second problem: The count result should include only published children.

Example 1 with 2 children published (2 children have a reference to the parent):

Title of parent node | 2

Example 2 with 1 child published (2 children have a reference to the parent):

Title of parent node | 1

Sorry if it’s not totally clear, it’s hard to explain

Above all of this, if the result could be sortable it will be a good news but I don’t think it will be possible…

Thank you

postgresql – Count on has_many associated records only if the has_many tables have two records with given names

I have the main table on which I have to apply count. I have two bridge tables and two nested tables for has_many relation. You can generate tables and bridge tables with below code and also insert some data

CREATE TABLE main_table
(
    id        serial PRIMARY KEY,
    is_active BOOLEAN,
    name      VARCHAR(50) UNIQUE NOT NULL
);

CREATE TABLE nested_table_1
(
    id   serial PRIMARY KEY,
    name VARCHAR(50) UNIQUE NOT NULL
);

CREATE TABLE nested_table_2
(
    id   serial PRIMARY KEY,
    name VARCHAR(50) UNIQUE NOT NULL
);

CREATE TABLE bridge_table_1
(
    main_table_id     INTEGER REFERENCES main_table (id),
    nested_table_1_id INTEGER REFERENCES nested_table_1 (id)
);

CREATE TABLE bridge_table_2
(
    main_table_id     INTEGER REFERENCES main_table (id),
    nested_table_2_id INTEGER REFERENCES nested_table_2 (id)
);


INSERT INTO main_table (is_active, name)
VALUES (true, 'main 1');
INSERT INTO main_table (is_active, name)
VALUES (true, 'main 2');

INSERT INTO nested_table_1 (name)
VALUES ('Contact');
INSERT INTO nested_table_1 (name)
VALUES ('Dropley');

INSERT INTO nested_table_2 (name)
VALUES ('nested table second 1');
INSERT INTO nested_table_2 (name)
VALUES ('nested table second 2');
INSERT INTO nested_table_2 (name)
VALUES ('nested table second 3');
INSERT INTO nested_table_2 (name)
VALUES ('Drop');

Query

SELECT COUNT(main.id)
      FILTER (where nes_2.name IN ('nested table second 1', 'nested table second 2') AND
                    nes_1.name = 'Contact')                              AS contact_compliants,
      COUNT(main.id)
      FILTER (where nes_2.name = 'Drop' AND nes_1.name = 'Dropley')      AS droplet_compliant,
      COUNT(main.id),
      COUNT(main.id) FILTER (where nes_2.name IS NOT NULL AND
                                    nes_1.name IN ('Contact', 'Droplet')) AS total_opportunities
FROM main_table AS main
        INNER JOIN bridge_table_1 AS bt_1
                    ON bt_1.main_table_id = main.id
        INNER JOIN nested_table_1 AS nes_1
                    ON bt_1.nested_table_1_id = nes_1.id
        INNER JOIN bridge_table_2 AS bt_2
                    ON bt_2.main_table_id = main.id
        INNER JOIN nested_table_2 AS nes_2
                    ON nes_2.id = bt_2.nested_table_2_id
WHERE main.is_active = 'true';

The query above is working all great counting everything fine. Just one issue. In the first part for contact_compliants, it has IN which means either one of the names for nested will increment count. which is not my requirement. I want to count only when when both the names matches.

to be clear: How do I make this part where nes_2.name IN (‘nested table second 1’, ‘nested table second 2’) to count only when nes_2.name = ‘nested table second 1’ AND nes_2.name = ‘nested table second 2’). I have tried adding double join so that I can compare but no success. I have also seen similar solution but I am not sure, how it will apply here with Having

sql server – Average Waiting Tasks Count / Resource Waits

I’m trying to help troubleshoot a sudden performance problem with SQL Server 2014 SP2 (12.0.5659.1). I don’t have details on what exactly the scheduled stored procedures are doing, but I know that the SP(s) with problems are using OLEDB and remotely querying a SQL server to refresh local tables. Execution that used to run for less than an hour, now takes days, basically never completing. We’ve verified that no physical network issue exists.

Looking at the Activity Monitor the things that stand out are:

Waiting Tasks averaging 9 or 10.

Network I/O and SQLCLR both have Wait Times in the 2000-4000 ms/sec with avg Waiter counts of 3 or 4.

The Cumulative Wait Times on both SQLCLR and Network I/O are in the neighborhood of 500K seconds.

Latch also looks pretty high 2600 ms/sec, waiter count at 3-5.

Are these way out of line or am I barking up the wrong tree?

algorithms – 1230C | Codeforces | Find count of numbers that divide all numbers in an array

Here is the question: Link. In a gist, we need to count the total count of numbers that would divide every number in an array.

The approach that I took was that any number that has to divide all the numbers must be less than or equal to the smallest number in the array. For e.g., if the array is (6 90 12 18 30 18) – any divisor cannot be greater than 6, because that would not divide 6.

Based on above logic, here’s the code that I wrote:

#include <bits/stdc++.h>

using namespace std;

//output
#define output(x) cout << x << endl
#define ll long long

int main(int argc, char const *argv())
{ 
    int n;
    cin >> n;

    vector<ll> v(n);

    ll smallest = LONG_MAX;
    for (auto &it: v) {
        cin >> it;

        if (it < smallest) {
            smallest = it;
        }
    }

    set<ll> divisors;

    for (ll i = 1; i*i <= smallest; i++) {
        if (smallest%i == 0) {
            ll q = smallest/i;
            divisors.insert(i);
            divisors.insert(q);
        }
    }


    for (auto &it: v) {
        vector<ll> removeEl;

        for (auto &div: divisors) {
            if (it%div != 0) {
                removeEl.push_back(div);
            }
        }

        for (auto &rem: removeEl) {
            divisors.erase(rem);
        }
    }

    output(divisors.size());


    return 0;
}

This fails (wrong answer) on some test case – is there something incorrect in my implementation or my approach to the question?

mysql count instances and split by value in separate column

I have a football database that contains a ton of information, what I’m trying to do is count the number of times each team has scored against each other.

I can output all the goals that have been scored in the game easily, as well as count the number of rows that the table prints out. The trouble I’m running in to is when I want to instead run a query that outputs 2 different counts, where one is the number of goals scored in the list by X team, and the other by Y team.

This is my current query to count all goals by both teams

SELECT COUNT(g2.id) as 'Goals'
FROM games g
     join appearances a on g.id = a.game
     join players p on a.player = p.id
     join clubs c on a.club = c.id
     join clubs c2 on g.opposition = c2.id
     join goals g2 on a.id = g2.appearance
     join competitions c3 on g.competition = c3.id
WHERE
     c2.name = 'teamX';

mysql – how to display item wise count report using SQL query

I Want to write a query for a particular result

created a table with three columns
1.Category(items value-Water pump,cutting motor,driller)
2.purchased Date(value-date)
3.Working properly(value-(Yes/No)

want no. of items in each category with month wise report(working or fault)

8 – View only displays nodes that has comments when adding comment count field

On drupal 8 I am facing an issue with views.
I created a view listing all nodes of a certain content type.
I added basic fields, Title, Date content was created, and a read more link.
The view works fine with these fields, but when i add Comment Statistics: Comment count, all nodes that don’t have any comment don’t show up in the view.
It only lists nodes that received comments.

Any idea on how to fix this ? Am I doing something wrong ?

Thanks

full node – Mempool count is too low

I’m running a full node. I wanted to get a list of all mempool txs (using getrawmempool false), and found that it only came back with around 3000, where all the block explorers are currently showing around 12000. I understand that mempools will differ between nodes, but this seems like a very big difference. Can I do anything about this?

Edit: Here is getmempoolinfo:

"size": 1985,
"bytes": 3458091,
"usage": 10785216,
"maxmempool": 300000000,
"mempoolminfee": 0.00001000,
"minrelaytxfee": 0.00001000

What is the probability of having forks in PoW given different network size (miners count)?

Given a network of k miners, what is the impact of k on the probability of having forks in Bitcoin or any PoW-based blockchain?

It is clear for me that a network with fewer miners will have less probability of having a fork than a network with higher number of miners.

Is there any mathematical formula that shows this relation?

Count occurrences of a specific word in Google Spreadsheet

I have some cells with text. I need to count the occurrences of a specific word from those cells.

Example sheet:https://docs.google.com/spreadsheets/d/1WECDbepLtZNwNfUmjxfKlCbLJgjyUBB72yvWDMzDBB0/edit?usp=sharing