Skip to content
Advertisement

Tag: mysql

Count occurrences of distinct values

I am trying to find a MySQL query that will display the number of occurrences of an ID value within a year. Table: Expected output: I’m trying with the something along the lines of following sql query, but it gives me nothing like the expected output. It’s the 3rd column im struggling with. How can i create that 3rd column?

How to unify three different queries in mysql when exists multiple criteria?

I have a table and I need to get the number of rows using different criteria. Currently I use 3 queries one after another: SELECT COUNT(status) FROM projects WHERE project=’1′ SELECT COUNT(status) FROM projects WHERE project=’1′ AND status>’10’ SELECT COUNT(status) FROM projects WHERE project=’1′ AND status>’20’ How do I merge these queries into a single query? P.S. There are 30

how to show decimals in sql instead of 0

I am trying to get the percent and it just shows up as zero. I want to show two decimal places such as 0.65 Here is a piece of the query I am selecting: if I use this it shows up as 0 and gets rid of the rest Answer Meanwhile, I question whether COUNT(numbers) is what you want. That

MySQL order by field in Eloquent

When I want to define a custom sort order in a MySQL query I can do something like this: ORDER BY FIELD(language,’USD’,’EUR’,’JPN’) What would be the Eloquent ORM version of that? UPDATE: This is …

MySQL Query join last comment to topic

I have a topic and topic_comments table. I want to join them both. The join is on topic.id = topic_comments.parent_id. I want to show the topic with latest comment and order by latest comment createdate. And not show duplicate topics. Can anyone help me? So far I have this: This however doesn ‘t show topics without comments. It only returns

Query to check if a certain row has 2 words

How to return rows where a column has 2 words (that is, strings separated by a space) in it? It must be purely using SQL. Answer I dont know the names when querying. Its a big dataset. I only have to check if the name contains a spacebar basically (from a comment). If you want to distinguish names that have

Advertisement