SELECT CAST(`last_charged_date` AS DATE) AS Date_time, COUNT(*) AS Charged_Count, SUM(last_charge_amt) AS Revenue FROM subscriber GROUP BY CAST(last_charged_date AS DATE) SELECT CAST(…
Tag: database
Select everything that has only one value in a relation
Okay, so here are my tables: tests: +—-+————+ | id | name | +—-+————+ | 1 | test-one | | 2 | test-two | | 3 | test-three | | 4 | test-four | | 5 | test-five | | …
Arithmetic operation on the subsets of results from a SQL groupby statement
I have a schema with sex(m/f),state_name(all states of a country), student_name,and education (phd,ms). I use following query to return total males or females in each category of education for every …
MySQL query result does not return some rows that should be in the result
This is a query that should return a match result of a lost item that has been found. According to my database below, I expect it to return two rows, but only one row is returned. Before I added the second rows in tbl_lost_items and tbl_found_items the result was an empty set. This is the result These are my tables
Getting wrong sum when using group by with inner join
With reference to this question (How to get the sum in a joined table when using group by – getting wrong results) I have two tables orders and order_items. I need to group the results by days. But I also need to get the sum of energy_used for each day from another table. When I try that using a join,
how to create pl sql function to Checking if data exists in database or not
I am trying to create a function that tells whether data exist in database or not. Trying to solve this using cursor if data exist then data will be fetched from database and value of temp will be TRUE otherwise data would not be fetched from DB and it will set value of temp to false. But when I compile
I have a trigger on my SQL Server table which takes user updates and log them, in case we need to revert, but it has a problem
The problem is, sometimes in a day that no one is changing anything, a random user just enter the page and the trigger saves a change. The problem is, not only it logs a change that never has occurred …
How to Count Times an ID Appears in a Column in a Different Table
Apologies in advance: I’m sure this is relatively easy and has been asked ad nauseam, but I just can’t quite come up with the proper search. Basically, I’m trying to take a list of IDs queryed from …
Query for students passed or not passed in specific Subjects [closed]
I have a Table with Column Headings: ID Student_Name Roll_Number Subject1MarksObtained Subject1TotalMarks Subject2MarksObtained Subject2TotalMarks Subject3MarksObtained Subject3TotalMarks …
Ruby Foreign Key Constraints in Database vs Model
I have the following models in a Rails app. This setup has worked fine since normally when I would like to add a new VendorPromo to a vendor, there’s a dropdown in the view of available Promos to choose from. Now, I’m enabling the creation of new VendorPromos via an API. However, this current set up will allow the creation