Skip to content
Advertisement

Tag: sql

SQL Query count of values

I’m trying to write a query that will show the number of times some specific values are present per node Here is my table: I’m trying to query the count of nodes for the number of times the values in channel_width show up. For instance, the amount of nodes ’32’ show up once and ’64’ shows up 3 times, the

SQL multirow data on one row

I almost never ask a question, so please be patient with me. Example Orders table: Order_ID Ord_Partno Ord_UnitPrice Ord_Qty 1658712 PN001 $1.20 9 1658712 PN002 $2.40 4 1658712 PN003 $1.40 21 1658712 PN004 $1.10 16 Example Inventory table: Inv_Partno Inv_Warehouse Stock PN001 Atlanta 14 PN001 AtlantaHold 0 PN001 Chicago 7 PN001 ChicagoHold 0 PN002 Atlanta 5 PN002 AtlantaHold 18 PN002

Output of non-existent values when grouping in sql

For example, i have a table with the data: Screenshot This table named “table”. I have the SQL query: And I get the result: Question: how do I write a query that would return all the values that are in the kind field (or any other field that can be in group by)? Even if this value is 0. For

What’s the best way to “append” to a list of strings stored in a JSONB column in a table PostgreSQL such that duplicates are not stored

Say there is a table employee One of the rows has the following information in the tags column Currently to update the column with additional values I perform the following query However this adds duplicates to the cell and makes it look like which is less than desirable for my use case. Currently to circumvent this I’ve handled duplicates in

Is it possible to use result or state of query in same query

For example I have this table events: user_id event_type date_of_event userA X 01-01-2000 userA Y 01-01-2005 userB X 01-01-2000 userB Y 01-01-2100 I want to select all users that have an event_type = X but no event_type Y in the next 2 years AFTER the date of event_type X. So in the table above that would be userA and userB

Trying to find the max observation by group

I have the below code where I am trying to find a patients injury level and whether it is between 1 and 5 or 6 and 10. I have used the ‘case when’ clause below. The issue is, some patients have multiple injury levels. Is there a way for me to only get the max injury level and ignore the

Converting a SQL query to SEQUELIZE

I am trying to wrap my head around creating this sequelize query. I have been able to create 2 separate queries where the ‘order by filter’ works and ‘aliases’ work, but not combined. This is what i currenty have in sequelize Answer You just need to use fn twice: in order and in attributes options: Also you can combine findAll

A better way to get the last character

I have been working in an exercise, I have 2 values (one with 9 characters and the other with 8) and I have to show 3 columns. The original number The number without the last character Only the last character The Query works but I would like to know a way to improve how I get the last column, I

How do I join a string and an int in PostgreSQL?

I have a procedure with an int parameter. The syntax for the add_retention_policy function is add_retention_policy(‘hypertable’, INTERVAL ‘x days’, true). I want to prefix the hypertable with the schema which is always ‘schema_’ and then followed by the id parameter, how do I do that? Answer You just need to rewrite the INTERVAL part in your function call as days

Advertisement