Skip to content

Tag: sql

How to use a calculated value in Oracle SQL count

I have a column called BIRTH_DATE in my view. I want to calculate the age using that column and today’s date, and count the number of staff in an age bracket. For example: staff between 40 and 49 etc. Other answers in plain SQL statements are also welcome. My code is shown below: I am calculating the ag…

How to Sort this MySQL Query

I am trying to insert the ORDER BY in this query to sort the Total column: With the following result: Here’s what I have tried so far but no luck: Answer I think you want: Rationale: the ORDER BY clause should go after all UNION ALL subqueries – so it needs to be outside of the GROUP_CONCAT(), in …

SQL Group by Transpose

I have the following Table charges Using the following query gets my the counts by Charge and Date Is there a way to transpose this to get the following? Thank you. Answer Use conditional aggregation:

Multiple LIKE clauses in Laravel Eloquent

I currently have this code in my controller: The above code works, but what I want is to get “Accounting” and “Web Design” from an array, and just loop through that array so that the query is dynamic instead of hard coded on the controller Answer Try this :