I’m trying to create a view that contains a column with a list of codes. This is the SQL code that I currently have: This creates a view with this column: ?column? code1 code2 code3 As you can see the column name is “?column?” and I would like to change it to a name of my choice. I’ve tried looking
Tag: database
SQL Filter by dateTime
day is a integer variable. If I set the day value to 1, database is filtering for 24 hours. But if I set the day value to 1, I only want to see the logs of the new day. How can I do that? Thank you for your help. Answer
how to copy values from a column to a non-existent column in postgresql
i have a table like this: and i want to copy the values from the first column to the non existent column that is ‘qty’ how do i do that if they have different data type? what i originally wanted is when the 1st column’s value is 0, then the column qty should be blank or empty, not [null], i
Count from 4 tables with join and null values
Tables: What I am expecting to query is this: However this is what I get: With this query: I wonder, in what way the query above could be modified to return the expected results? What would be a good approach to achieve this? Answer You are joining along two dimensions, so you are getting a Cartesian products. That is simply
PostgreSQL – Find number of installs each day given a table of installs and uninstalls
I have a table for machine installations in this way: I need a query that returns the number of installed machines per day. Like this: I know that given a date, say ‘2020-01-03’, I can get the number of installed machines as follows: However, I do not know how to query in such a way I can get the result
How to combine 4 sql queries into a single query with good performance?
I have a problem to solve. First I split this problem into parts and so I wrote four queries separately but now I need to put them together as if it were a single call to return a single result. How can I do this? 1) I select purchases according to branch and store 2) I validate if the promotional
How can I show values with zero in a Group By query
I am trying to get the zero values from my status table associated with the case of one user. So, I have this query that returns me only one value because, I have only one case associated with one status but I want to receive also the another status with value 0. So I have the status ‘Open’ and ‘Closed’
SQL Query creation with multiple joins
I am working with MYSQL, and want to create a query. I have 3 tables. QUESTION QUESTION_NUMBER QUESTION_DESCRIPTION 1 anydesc 2 anydesc2 ANSWER ANSWER_NUMBER ANSWER_DESCRIPTION 1 anydescANS 2 anydesc2ANS 3 anydesc3ANS And a bridge TABLE QUESTION_ANSWER Q_NUM A_NUM 1 1 2 2 2 3 Now I want to retrieve all the Answers of let’s say a specific QUESTION NUMBER i.e
GROUP BY with Key:Value filters for each group
Given a table with following schema: RecordId ProcessId Data 80830F00-379C-11EA-96B7-372060281AFC 1 4.2 80830F00-379C-11EA-96B7-372060281AFC 2 445588662211448 80830F00-379C-11EA-96B7-372060281AFC 7 1 791F6D30-379C-11EA-96B7-372060281AFC 1 3.3 791F6D30-379C-11EA-96B7-372060281AFC 2 999999999999999 791F6D30-379C-11EA-96B7-372060281AFC 7 2 So the RecordId represents some grouping key and each ProcessId has its Data. Now I have a filter which looks like this: So the key is ProcessId and value is Data. Question How
How to union current table and history table order by recent edit
I am currently working on preparing audit table and the output structure I am planning to have is, latest record from current table and followed by associated(id) records from history table for all the records. So that user can see the latest changes and its history. At present I am using UNION of two tables and ORDER BY id but