I have a table with values like so: I want to do a GROUP BY based on ts and display the counts for distinct values of usr_id like below. ts count of A count of B count of others 11 2 1 3 22 0 1 0 33 1 0 3 http://www.sqlfiddle.com/#!9/bbf4fc/2 I couldn’t make much progress beyond doing the
Tag: sql
sql: exclude rows if at least one row within it isn’t in the list
I have the following simple table COL1 COL2 COL3 U1 L1 X U1 L5 X U2 L2 X U3 L2 X U4 L4 X U4 L6 X U5 L7 X when I execute the statement Result: My desired result is The U1 and U4 should be filtered out because one of their COL2 contains an element which is not in
select the last 30 days of POSIXct dates in R
Probably simple, but this is my first time working with POSIXct date format. I have a table of orders (that i got from a syl database) and I would like to select all rows of the last 30 days. so today’s date minus 30 days. my date is of the type POSIXct. Now, I know how to do this selection
How to divide a value of a column to the total value of that column for every row in SQL?
I’m new to SQL and have a basic question. I’ve two columns as Name and Salary and their values Name Salary Amit 1000 Harsh 2000 Priya 5000 Priya 4000 I want to create another column name count and rate. For count – I want the count of names in the table For Rate – I want to find the value
How to solve this specific SQL query? My solution also returns not wanted values
I have three tables in my DB: “Film”, which contains details regarding movies “Sale”, which contains details regarding theathers where movies are projected “Proiezioni”, which contains details regarding projections, with external references to both the previous tables The problem involves finding the titles of all the movies that were projected in the city of “Pisa” only. The problem of this
Calculation using SQL server
Formula used This is the formula that I used to calculate Expressed as a single equation: Code that I tried Correct answer should be 123. Any clue what I am missing in the query? Answer According to this site your equation is kinda wrong. Please be sure to add ^ to display the “to the power of”. Also this result
Update column value where property of foreign key table is equal to property of foreign key table
I am looking to do an update basing myself on the property of another table to which my initial table has a foreign key to, so given the case I have 3 tables: Is there a way for me to do something like The reason I cannot use the Id even knowing it is that I am dealing with different
python how to write an update sql query?
I am trying to write an update query but I could not manage the string. My connections is ok. My query is like this: This is giving me error: undefined column name ‘hello’. I want to update message column as hello but it is getting it as a column name. In sql, when I write it as UPDATE users SET
How to create pivot table entries for all of the rows available in two separate tables in MYSQL
I need help to create pivot table entries for all of the rows available in two separate tables, basically, I have two separate tables as services and plans as below plans table id name description 1 plan one description for plan one 2 plan two description for plan two services table id name 1 service one 2 services two and
SQL get rows to colums only for 1 row. Pivot not possible
Stored procedure has 2 date parameters: I have to output the year-months per column in this selection. I extracted a string with all these months: Output is a single column with @cols in it, but what I need is (in this case) 12 columns with first column [2020-01], second column [2020-02] etc. (@cols is not static, it varies with the