I have transaction table as below “I want number of newly registred customer who did their first transaction on Store1 during July 01 – July 30” In this case the expected result is 1 which is CustomerID B with OrderID 4 How to query out the data with using EXISTS / NOT EXISTS, but not using …
Tag: sql
How to write sql query to get this result
I had two tables as below: request_id update_from_id sw_ref_number raised_by_user_id raised_date 1 0 1 3 2019-08-29 15:08:16.000 id request_id input_id value is_deleted 21 1 1 00001 0 22 1 2 3 0 75 2 1 00002 0 76 2 2 0 My query is: And after that my result is: request_id sw_ref_number value input_id 1 1 00001…
Pulling out monthly daypart data
I’m dealing with sales data that looks like this Date Time Net Amount Store No Item Category Code 2021-03-21 00:00:00.000 1754-01-01 08:01:14.627 100 001 FOOD 2021-01-31 00:00:00.000 1754-01-01 15:42:21.670 120 002 FOOD 2021-04-24 00:00:00.000 1754-01-01 17:35:30.070 160 002 FOOD 2021-03-14 00:00:00.000…
How to order by multiple columns not creating different groups using Laravel eloquent
I have a table which looks like this: Name AltName Sam null Ann null null Mark John null null Bart Sasha null I want to order by both Name and AltName. If I do this: This will return the data in this order: Ann, John, Sam, Sasha, Bart, Mark I don’t want it to group the data but instead merge
Field value counts with aggregate conditions
Suppose I have the following applicant data for jobs in a company: The budget is 40000 and the preference is to hire senior managers. What PostgreSQL constructs do I use to get the following result as far as the number of hires are concerned. Any directions would be appreciated. Here is a starting sqlfiddle: …
How do I insert data into a table where one of the values should be a foreign key from another table?
I wanted to update the post table (main table) with those data: However, the post table userid column only accepts an integer (foreign keys from the user table (userid)), not username string itself. How can I do this with INSERT, SELECT/WHERE query? There are the tables. post user Here is what it should look …
Powershell, invoke-sqlcmd, export-csv fails to show data if there is more than one result
I have the below code to get data from a SQL DB and export it into a CSV file: This works perfectly if there is one result. But if there is more than one result, it will show the below in the csv file I am at my wits end as to why it is doing this. It’s obviously the
SQL query not returning all possible rows
I am writing a simple SQL query to get the latest records for every customerid. My SQL query – Sample data: customerid device_count date_time A 3573 2021-07-26 02:15:09-05:00 A 4 2021-07-26 02:15:13-05:00 A 16988 2021-07-26 02:15:13-05:00 A 20696 2021-07-26 02:15:13-05:00 A 24655 2021-07-26 02:15:13-05:…
SQL Subquery as expression
I have the following two tables: I want to be able to return all the claims that are a specific FormType and AdjustmentVersion. Given the following query: How do I correct the syntax to match the AdjustmentVersion on the given integers and the subquery at the same time? Currently, I am getting error ‘Su…
Can * be used for partial topics in AWS’ IoT Rule syntax?
Is this allowed as AWS’ IoT Rule syntax?: Answer No, you cannot use a * to achieve this, since you must pass a valid topic filter. According to the documentation you are able to use a + sign to achieve this effect. Quoted from the documentation linked above: A subscription to sensor/+/room1 receives mes…