I'm using the following query to get all claims/statements for an item, like for instance for the band Build To Spill.
https://w.wiki/3n3H
Some of the values, like Boise, indie rock, etc. , are items by themselves. How can I display their QID if available using my query?
Related
I have my table like this
user_Id
survey
1001
{"What are you interested in?": "[Games]", "How do you plan to use Gamester?": "[Play games, Watch other people play, Connect with other gamers]" }
1001
{"What are you interested in?": "[Coupons]", "How do you plan to use Gamester?": "[Watch other people play]" }
1001
{"What are you interested in?": "[Games]", "How do you plan to use Gamester?": "[Play games]" }
I want to group by second field How do you plan to use Gamester? And have output like below
Option
Count
Play games
2
Watch other people play
2
Connect with other gamers
1
All the examples I found were for String fields and not for array. Tried few thing but not working. Kindly help how can I group on array field values in josonb column and get count.
Your json data array in the How do you plan to use Gamester? property is wrong. Since you are storing a string and not an array of values.
Replace all values as shown below:
Source Format: "[Play games, Watch other people play, Connect with other gamers]"
Required Format: ["Play games", "Watch other people play", "Connect with other gamers"]
After fixing your data, you can use the jsonb_path_query function and return a list of values from the desired property, and then group them.
with cte_plan as (
select
jsonb_path_query(survey, '$."How do you plan to use Gamester?"[*]') as option
from my_table
)
select option, count(option) from cte_plan group by option;
Result
option
count
Watch other people play
2
Play games
2
Connect with other gamers
1
Demo in DBfiddle
When I was trying to create a dashboard in Qlikview, I write a statement to show up the following product data in a bar chat:
As you can see in the pic, however, the is a null value product to be counted.
I write the following statement in the Expression of Qlikview BarChart:
Count({<PRODUCT={'Enoxaparin Sodium','Insulin Glargine 300','Non-Promotional','Sevelamer Carbonate'}>}DISTINCT CALLID).
It can display what I want to see, but some other product may be missing in the future counting.
Who can tell me how to write an expression to count all the product without couting Null Value in Product Field?
I input like this Count({<PRODUCT={'<>NULL'}>}DISTINCT CALLID), but it didn't work.
I have resolved this problem by doing this:
count(distinct if(Not IsNull(PRODUCT),CallId))
im analyzing some e-sports soccer championship data.
My original table looks like this:
Every row corresponds to one match with the Date, Players envolved, the Teams they used and their Scores
my df head()
After seaching around tableau community, I pivoted "Player A" and "Player B" columns so i can filter for players individually. Now any match has 2 rows(one for each player on that match) and tey're unified by the 'MatchID' column:
my tableau table
That said, i want to build a view where the viewer could select two players and see statistics about all the matches they played against each other, like these two:
1- Last 10 matches info (Date, teams they played with, scores)
2- Most-frequent results like this graph:
the graph i want to show
Tried bringing some dimensions to colums but i really couldnt find a way to show the entire row data in a view. No idea about h2 filter from two players and take only matches where they encounter using MatchID.
I tried searching around and do some Calculated Fields filters, but i just went Tableau with no background in SQL, Excel or anything, just Python. So im a bit lost with so many options and ways.
If anyone could gimme directions about that i would be very happy. Thx in advice (:
I think you should unpivot your data so you are back with 1 record per match. Then you will be able to use 2 parameters as your filters; one parameter for player 1 and the other for player 2. That would enable the user to select 2 different players.
As there's a chance the same player could be in both the Player 1 and Player 2 columns, to use as a filter is a little more complex. Your filter calculated field for the Player1 parameter would be something like:
[FilterParameterPlayer1]: [ParameterPlayer1] = [Player1] OR ParameterPlayer1] = [Player2]
And for Player2 parameter:
[FilterParameterPlayer2]: [ParameterPlayer2] = [Player1] OR ParameterPlayer2] = [Player2]
Both filter fields should be set to only show True.
I know there has been a lot of discussion around this subject but I cannot find anything that points me in the direction of a definitive answer.
I have the below sql statement within a .net page in Webmatrix:
SELECT vehicle, vehicleDescription, count(vehicleDescription) AS 'Total'
FROM vehicles
WHERE (branchRequirement = 'Manchester')
AND (deliveryBranch = 'Manchester' OR deliveryBranch IS NULL)
AND (dateDeliveredToBranch > GETDATE() OR dateDeliveredToBranch IS NULL)
AND (vgc LIKE 'B_') GROUP BY vehicle,vehicleDescription
The output is obviously GROUPED data for the chosen conditions.
What I am trying to do is provide a link in my Webgrid on the .net page which allows the user to open a child page with details of the GROUPED vehicles.
Where I'm getting stuck is I cannot include the vehicleID in the GROUP BY because they are obviously all UNIQUE.
Has anybody come across this or something similar with any degree of success as I am pulling my hair out with it which I can ill afford to do!
Thanks
M
I have come across similar issues and the solution I came up with was to use the information you already have. When the user clicks on the link, you know the vehicle and the vehicleDescription that the user wants to see. You should not need the vehicleId because you are not going to have one unique result. If they click on a vehicle that has a count of 3, the child page should have details about all 3 results.
In order to find the 3 results the user would want to see, you can alter your existing query and use it for the child page. The altered query should take the vehicle and vehicleDesciption as parameters.
SELECT *
FROM vehicles
WHERE (branchRequirement = 'Manchester')
AND (deliveryBranch = 'Manchester' OR deliveryBranch IS NULL)
AND (dateDeliveredToBranch > GETDATE() OR dateDeliveredToBranch IS NULL)
AND (vgc LIKE 'B_')
AND vehicle = #vehicle
AND vehicleDesciption = #vehicleDescription
Pass the parameters in .Net and you should end up with the same data that you summed in your last query, since this query is essentially the same.
Okay, I'm using WordPress, but this pertains to the SQL side.
I have a query in which I need to filter out posts using three different categories, but they're all terms in the post.
For example:
In my three categories, I select the following: (Academia,Webdevelopment) (Fulltime,Parttime) (Earlycareer).
Now what I want to do is make sure when I query that the post has AT LEAST ONE of each of those terms.
CORRECT RESULT: A post with tags Academia, Fulltime, Earlycareer
INCORRECT RESULT: A post with tags Academia, Earlycareer (doesn't have fulltime or parttime)
Currently, my query looks something like this:
SELECT * FROM $wpdb->posts WHERE
(
$wpdb->terms.slug IN (list of selected from category 1) AND
$wpdb->terms.slug IN (list of selected from category 2) AND
$wpdb->terms.slug IN (list of selected from category 3)
)
AND $wpdb->term_taxonomy.taxonomy = 'jobtype' AND .......
When using this query, it returns no results when I select across the different categories (that is, I can choose 4 things from category 1 and it has results, but I can't choose anything from category 2 or 3. And vice versa)
I'm not sure if this is something to do with using IN more than once on the same column.
Thanks in advance for any help!
Your query seems to be correct. There is no any limitations in SQL about using IN for the same column miltimple times.
But ensure that you don't have any NULL values in your list of selected from category 1/2/3 queries. Even single NULL value in these lists will give NULL as a result of whole 'WHERE' condition and you will get nothing as a result.
If this won't help then it must be WordPress issue.